c# - .NET string IndexOf unexpected result -
/ P> I'm trying to start it:
< P> Which Return -1 str.IndexOf ("se \\\" & gt; ")
is not searching for this option?
Note: 5x \ 'was shown for a while because the snippet was edited, the original had 3 lines.
Your code actually returns from '\\' & gt; Searching for '
. When searching for strings with backslashes, I usually find it easy to use literal strings:
str.indexOf (@ "se" "> & gt;")
In this case you also have a quote in the search string, so there is still something to avoid, but I find it easier to read it individually.
Update : My reply was based on editing which, based on the IndexOf
current version of the parameter, I used the str
I do not just keep that required character sequence. Comment on this answer based on
Update 2 : This is a matter of some confusion about the role of '\' character in the string. When you observe a string in the Visual Studio debugger, it will be displayed along with the escape of Y characters.
Therefore, if you have a text box and type 'c: \' in it, then inspecting text property in the debugger will show 'c: \\'. An extra backslash has been added for escape purposes. The actual string content is still 'c: \' (which can be verified by checking the property of string length
; it is 3, not 4).
If we take the following string (taken from the comment below)
& quot; '& Lt; Em class = \ & quot; Correct_conversion \ & quot; & Gt; One night's light & lt; / Em> & Lt; Br / & gt; & Lt; Br / & gt; & Lt; Table width = \ & quot; 100% \ & quot; & Gt; & Lt; Tr & gt; & Lt; Td square = \ & quot; True \ & quot; & Gt; Ingrid & lt; / Td> & Lt; / Tr & gt; & Lt; / Table & gt; ') & Quot;
... \ "
Sequences are simply avoided by quotation marks, backslash strings are not part of content. Therefore, you can actually enter ' Looking for '& gt;'
from "> & gt; '
. Any of these will work:
str.IndexOf (@ "se" "& gt;"); // varitimam string; doubling it by str.exexOf (" Avoid quotation marks by using "regular"; regular string; backslash
Comments
Post a Comment