?
Solved

syntax for C# were i need to have idx = urlstring.IndexOf("<div class="comp2_tab_top"><p>"); pharsed correctly

Posted on 2011-10-11
8
Medium Priority
?
338 Views
Last Modified: 2013-12-16
i am trying to get the below code running but the syntax does not like the "   " in the statment.
I imagine that there is some syntax to put around the " so that it is not seen as a " to finish the line so that i can search for this sting in the recieved text

idx = urlstring.IndexOf("<div class="comp2_tab_top"><p>");

any help woudl be appreciated
0
Comment
Question by:sydneyguy
  • 3
  • 3
  • 2
8 Comments
 
LVL 16

Accepted Solution

by:
Easwaran Paramasivam earned 1000 total points
ID: 36953567
idx = urlstring.IndexOf("<div class="comp2_tab_top"><p>");

should be written as

string ToBeSearched = @"<div class="comp2_tab_top"><p>";
idx = urlstring.IndexOf(ToBeSearched );

0
 
LVL 3

Assisted Solution

by:Rouneh10
Rouneh10 earned 1000 total points
ID: 36953835
Use escape-character '\' to accomplish what you need.
string.IndexOf("<div class=\"comp2_tab_top\"></p>")
0
 

Author Comment

by:sydneyguy
ID: 36954390
neither of these work the teststr  = "<div class=\"comp2_tab_top\"><p>"
so when the sting get looked for it does not see "<div class=\"comp2_tab_top\"><p>"
which i know exists,  but still not working, i know the string is in the text but if it does compile it still sees the \ in the string and is different from what i am looking for
and the @ does not work and just does not compled

string teststr = "<div class=\"comp2_tab_top\"><p>";
or string teststr = @"<div class=\"comp2_tab_top\"><p>";
            startloc = urlstring.IndexOf ( teststr );
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:Rouneh10
ID: 36954432
Okay. Alternate solution is using @ like EaswaranP suggested and using double quotes when you need a single one:

string teststr = @"<div class=""comp2_tab_top""><p>";
startloc = urlstring.IndexOf(teststr)
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36954438
if you use @ you no need to specify escape character \ explicitly.

Use
string teststr = @"<div class="comp2_tab_top"><p>";
0
 

Author Comment

by:sydneyguy
ID: 36954469
it evaluates to

"<div class=\"comp2_tab_top\"><p>"

but it needs to evaluate to "<div class="comp2_tab_top"><p>"

so still not a direct build but we are getting closer
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36954495
Sorry above solution won't work.

You can have work around. Replace all <div class="comp2_tab_top"><p> with
<div class='comp2_tab_top'><p> in the source string.

Search index of below string.

string teststr = @"<div class='comp2_tab_top'><p>";

It will work. I tested.
0
 

Author Closing Comment

by:sydneyguy
ID: 36954509
bingo sorry for that yes it does work  @ ""  but it sees the \ in the debuger but it does not when it runs so tha configeration is perfect i rem that i have been caught with this before
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month14 days, 6 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question