Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace a double quote in a string with vbscript

Status
Not open for further replies.

Stone888

Programmer
Nov 22, 2001
2
DE
I want to remove the namespace from this tag using vbscript
Code:
string = < title xmlns:&quot;[URL unfurl="true"]http://www.w3.org/1999/xhtml&quot;[/URL] ></title >
so the tag looks like
Code:
string = < title >< /title >
I have used the following code but it will not replace the
namespace because the double quotes act in pairs.
I have tryed removing a small section at a time and trying using single qoutes in the replace statement, however I recieve syntax errors for both.
I have no control over the namespace as it is recieved from an external data source.
Code:
Replace(string,&quot;xmlns:&quot;[URL unfurl="true"]http://www.w3.org/1999/xhtml&quot;>,[/URL] &quot;&quot;)
Any ideas would be gratefully received
 
Thanks Mighty for your help,
Unfortunaetly it did not work , this is the error i got back from the browser

Error Type:
Microsoft VBScript compilation (0x800A03EE)
Expected ')'

xmlstring = Replace
xmlstring,&quot;xmlns:&quot;&quot; &quot;&quot;)
-------------------------------------------------------------------^


The arrows pointed to the first double quote basically is asume that it did not like them.
Thanks anyway..
I'll keep you posted if I sort it out.



Previous messgage
I want to remove the namespace from this tag using vbscript

string = < title xmlns:&quot; ></title >

so the tag looks like

string = < title >< /title >

I have used the following code but it will not replace the
namespace because the double quotes act in pairs.
I have tryed removing a small section at a time and trying using single qoutes in the replace statement, however I recieve syntax errors for both.
I have no control over the namespace as it is recieved from an external data source.

Replace(string,&quot;xmlns:&quot; &quot;&quot;)

Any ideas would be gratefully received
 
Thanks for your prompt reply, this also produced an error..see below
Line number and characture point to the quot before the semi-colon..any ideas

Error Type:
Microsoft VBScript compilation (0x800A03EE)
Expected ')'
/mozquito/examples/en/Craigs/xml-ui_demo/results.asp, line 128, column 68
xmlstring = Replace(xmlstring,&quot;xmlns:&quot;&quot; &quot;&quot;)
-------------------------------------------------------------------^
 
(xmlstring,&quot;xmlns:&quot;&quot; &quot;&quot;)
-------------------------------------------------------------------^

Whay have you got the two semi-colons in the replace command. If this is your string:

string = < title xmlns:&quot; ></title >

Then you need:

Replace(string, &quot;xmlns:&quot;&quot; &quot;&quot;)

You didn't have the semi-colon in your original post so that's why I didn't include it in the solution. Mise Le Meas,

Mighty :)
 
There is no semi-colon in my original, i only added it because you included it in your original relpy.
I'll remove it and check the result.
Thanks
 
There seem to be semi-colons going in at random - maybe the TGML formatting has something to do with it. Basically, you need to place the section of the string you want to replace within double quotes. If that string section happens to contain double quotes then just add an extra one.

So, without semi-colons, you have:

string = < title xmlns:&quot; ></title >

You need to use the following command:

Replace(string, &quot;xmlns:&quot;&quot; &quot;&quot;)

That should work. Mise Le Meas,

Mighty :)
 
Maybe I have this now...

You need a general-purpose routine to clean the namespace out of a tag. You don't know what the namespace will be, you just want to delete the blue in this example:

Code:
<title
Code:
_xmlns:&quot;[URL unfurl="true"]http://www.../xhtml&quot;[/URL]
Code:
 ></title >

Giving:
Code:
<title ></title >

{I added the underscore to show the space before
Code:
xmlns
.} Is that it?

How 'bout this example?
Code:
'Namespacegone.vbs
'
'Excise ONLY the namespace
'attribute from an XML element.

Option Explicit

Dim strOrig, lngStart, lngEnd, strCleaned

strOrig = &quot;< title xmlns:&quot;&quot;[URL unfurl="true"]http://www.w3.org/1999/xhtml&quot;&quot;[/URL] ></title >&quot;

'Find namespace attrib.
lngStart = InStr(1, strOrig, &quot;xmlns&quot;, vbTextCompare)
'Find 1st quote.
lngEnd = InStr(lngStart, strOrig, &quot;&quot;&quot;&quot;)
'Skip to ending quote.
lngEnd = InStr(lngEnd + 1, strOrig, &quot;&quot;&quot;&quot;)
'Take only what we want.
strCleaned = Left(strOrig, lngStart - 2) & _
             Mid(strOrig, lngEnd + 1)
MsgBox strCleaned
This can be pasted into a file as Namespacegone.vbs and tested.
 
Just an aside but you can also use a single quote inside of double quotes. &quot;string 'string inside'string&quot;. I have found this to work just fine.
 
You have to be careful.
Code:
str1 = &quot;This 'is' a test&quot;
str2 = &quot;This &quot;&quot;is&quot;&quot; a test&quot;

If str1 = str2 Then
  MsgBox &quot;Equal&quot;
Else
  MsgBox &quot;Sorry!&quot;
End If
Is this case you'd be &quot;sorry.&quot;

The use of &quot; and ' in VBScrpt as string delimiters is one thing, but as characters in their own right it is a completely different matter.
 
I must have misunderstood what you were asking. You can use the single quotes inside the doule quotes to set the inside double qutes aside as such'&quot;' thus it is seen as a string inside a string instead of an end to a string. Also there is always the old trusty &quot;Chr(66)&quot;. And try not to be so snippy to someone who is just trying to help.
 

FAO dilettante (MIS)
Thanks for your input on this your solution did not quite work in my program because my original string uses single quotes , but your solution has shown me how to overcome a slightly different problem..thanks very much

FAO SCoyote(programmer)
Your input is also appreciated , however , Im not too sure where Ive been snippy with anyone...
 
Since you are having so much trouble trying to get this to work, why not just delete the quote first?

string = Replace(string, chr(34), &quot;&quot;)
new_string = Replace(string, &quot;xmlns: &quot;&quot;)

Steve
 
I have managed to overcome this problem by removing the namespace entirely, hence there is no need to delete a section of the code anymore.
The namespace that actaully came through was incorrect, it was supposed to be a namespace associated with the Dublin Core (meta data inititive) schema, however the program was actually pulling the default XHTML 'Title' namespace used in the header of the webpage.
This was an error with the copy of the schema, I managed to edit the schema to correct the errors and allow the browser to pull through the correct Dublin Core 'Title 'namespace .This allowed the parser to interpret thte code correctly with no errors.

Thanks for for all the helpful tips regarding this subject..
I look forward to your help and hopefully helping other in this group in the near future.

C.Stone(programmer)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top