473,372 Members | 953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 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 10682
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: SK | last post by:
Hey folks, I am searching for a string (say "ABC") backwards in a file. First I seek to the end. Then I try to make a check like - do { file.clear (); file.get(c); file.seekg(-2,...
1
by: ra294 | last post by:
I need to search programmatically if a certain string appears inside a PDF or CHM file. The search is done only once for each file so I don't think that a solution to index the file using Index...
1
by: vinothg | last post by:
Hi , I have a binary file which contains 30,000 strings of 20 bytes each.I need to search for a string in the file to see whether the particular string exists. The sample code which i wrote...
3
by: Cplusplusbeginner | last post by:
I need to write a program to search a particular string in a specific file.e.g if the file is abc.dat which contains names of students in a class, I need to search for a particular name say John in...
3
ameesh1109
by: ameesh1109 | last post by:
hi, i want to search for a string in all the coloumns of all the tables in the database, i.e. i have a select query with a where clause but without a table name and without a coloumn name. can...
3
by: Paddy | last post by:
Lets say i have a generator running that generates successive characters of a 'string' characters then I would have to 'freeze' the generator and pass the characters so far to re.search. It is...
0
by: Tequilaman | last post by:
Hi everybody! I want to search some data string of 3 to 11 characters within a hich number of files. tese files are text files with names that are not .txt but .10F etc. All are in one ffolder,...
5
by: kanley | last post by:
I have a main table with a text description field. In this field, its populated with a string of data. I need to identify from this string of data the name of the vendor using some keywords. I...
1
by: dhivyacse | last post by:
i! how to create search engine inside the website only without using database
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.