471,319 Members | 1,296 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Search for Quote inside a string

Hi,

completeString = "<p><a href="http://www.google.com"> ..... "

Now I want to extract the link pointed out by href so I try to find the
position of first the href tag and then try to see where the quotes begin.

pos_tag = completeString.IndexOf("href", 0, completeString.Length);

pos_text_tag_start = completeString.IndexOf("\"", pos_tag,
completeString.Length);

but this last line gives me an error - how can I find the position of a
quote - " in a string?

I have also tried :

pos_text_tag_start = completeString.IndexOf(""", pos_tag,
completeString.Length);

Any help is appreciated.
Jan 5 '06 #1
8 10517
I think all of these will work:

"""" (four double quotes)
'"' (single quote, double quote, single quote)
Convert.ToChar(32)
(char)32

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
http://msmvps.com/windsor/

"temp" <te*******************@yahoo.com> wrote in message
news:up**************@TK2MSFTNGP14.phx.gbl...
Hi,

completeString = "<p><a href="http://www.google.com"> ..... "

Now I want to extract the link pointed out by href so I try to find the
position of first the href tag and then try to see where the quotes begin.

pos_tag = completeString.IndexOf("href", 0, completeString.Length);

pos_text_tag_start = completeString.IndexOf("\"", pos_tag,
completeString.Length);

but this last line gives me an error - how can I find the position of a
quote - " in a string?

I have also tried :

pos_text_tag_start = completeString.IndexOf(""", pos_tag,
completeString.Length);

Any help is appreciated.

Jan 5 '06 #2
Rob Windsor [MVP] <ro*****************@gmail.com> wrote:
I think all of these will work:

"""" (four double quotes)
'"' (single quote, double quote, single quote)


These two won't. You need:
@""""
"\""
or '\"'.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 5 '06 #3

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Rob Windsor [MVP] <ro*****************@gmail.com> wrote:
I think all of these will work:

"""" (four double quotes)
'"' (single quote, double quote, single quote)
These two won't. You need:
@""""
"\""


Doing "\"" doesnt work - see output from immediate window while debugging:
ompleteString.IndexOf("\"", pos_tag, completeString.Length)

'completeString.IndexOf("\"", pos_tag, completeString.Length)' threw an
exception of type 'System.ArgumentOutOfRangeException'

base {System.ArgumentException}: {"Count must be positive and count must
refer to a location within the string/array/collection.\r\nParameter name:
count"}

ActualValue: null

Message: "Count must be positive and count must refer to a location within
the string/array/collection.\r\nParameter name: count"

or '\"'.


Jan 5 '06 #4

"temp" <te*******************@yahoo.com> wrote in message
news:e8**************@TK2MSFTNGP15.phx.gbl...

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Rob Windsor [MVP] <ro*****************@gmail.com> wrote:
I think all of these will work:

"""" (four double quotes)
'"' (single quote, double quote, single quote)
These two won't. You need:
@""""
"\""


Doing "\"" doesnt work - see output from immediate window while debugging:
ompleteString.IndexOf("\"", pos_tag, completeString.Length)

'completeString.IndexOf("\"", pos_tag, completeString.Length)' threw an
exception of type 'System.ArgumentOutOfRangeException'

base {System.ArgumentException}: {"Count must be positive and count must
refer to a location within the string/array/collection.\r\nParameter name:
count"}

ActualValue: null

Message: "Count must be positive and count must refer to a location within
the string/array/collection.\r\nParameter name: count"


The problem is with the count, not with the character you're looking for.
You're trying to look from pos_tag to pos_tag + Length -1, which is beyond
the end of the string. Since you want to search to the end of the entire,
just use the two-argument form:

:pos_tag = 'completeString.IndexOf("\"", pos_tag);


or '\"'.

Jan 5 '06 #5
I believe regular expression would make things easier in your case.

Try something like this:
(?<Protocol>http):\/\/(?<Domain>[\w.]+\/?)\S*(?x)

And then you can parse the input string with
System.Text.RegularExpressions.Regex, which will probably save you tens of
lines of code.

A great tools called Expresso from Ultrapico can help you build a regular
expression visually. Worth trying in case you are not familiar with regular
expression.

Good luck!
"temp" wrote:
Hi,

completeString = "<p><a href="http://www.google.com"> ..... "

Now I want to extract the link pointed out by href so I try to find the
position of first the href tag and then try to see where the quotes begin.

pos_tag = completeString.IndexOf("href", 0, completeString.Length);

pos_text_tag_start = completeString.IndexOf("\"", pos_tag,
completeString.Length);

but this last line gives me an error - how can I find the position of a
quote - " in a string?

I have also tried :

pos_text_tag_start = completeString.IndexOf(""", pos_tag,
completeString.Length);

Any help is appreciated.

Jan 5 '06 #6
Hi,

ompleteString.IndexOf("\"", pos_tag, completeString.Length)

'completeString.IndexOf("\"", pos_tag, completeString.Length)' threw an
exception of type 'System.ArgumentOutOfRangeException'

base {System.ArgumentException}: {"Count must be positive and count must
refer to a location within the string/array/collection.\r\nParameter name:
count"}


Well, the error is pretty self explanatory, pos_tag is probably > 0
therefore pos_tag + string.Length > string.Length , therefore you get the
error, it's CLEARLY stated in MSDN !

Just do IndexOf( "\"" , pos_tag );

Now , I STRONGLY suggest you to take the advice of Ray and use a regular
expression instead, you can find the url enclosed in " or in ' or even
nothing.
To further complicate the things, you could have things like : <a href="#"
onclick="window.open('url');return false">

Have fun! :)
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 5 '06 #7

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:u1*************@TK2MSFTNGP14.phx.gbl...
Hi,
Hi

Now , I STRONGLY suggest you to take the advice of Ray and use a regular
expression instead, you can find the url enclosed in " or in ' or even
nothing.
To further complicate the things, you could have things like : <a
href="#" onclick="window.open('url');return false">

Did I miss something? I cannot see the post of Ray where he has suggested
regular expressions?
Have fun! :)
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Jan 5 '06 #8
Found Ray's suggestion (strange that I still dont see it in my news client,
but I see his post on a different site).

"temp" <te*******************@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP14.phx.gbl...

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote in message news:u1*************@TK2MSFTNGP14.phx.gbl...
Hi,


Hi

Now , I STRONGLY suggest you to take the advice of Ray and use a regular
expression instead, you can find the url enclosed in " or in ' or even
nothing.
To further complicate the things, you could have things like : <a
href="#" onclick="window.open('url');return false">

Did I miss something? I cannot see the post of Ray where he has suggested
regular expressions?
Have fun! :)
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Jan 5 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by ra294 | last post: by
3 posts views Thread by Paddy | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.