.net - Does String.IndexOf(Char) always point to the same Char? -


i'm reviewing existing code (converted c#). includes expression:

value.substring(value.indexof(symbol), 1) 

where symbol is char value, string. (yes, for each symbol char in value.)

as far can tell msdn identical to:

symbol.tostring 

(which faster).

can suggest situation when won't case?

note see "flaw" in code means may refer earlier version of symbol in value 1 we're considering, part of question: can ever matter?

(obviously solution rework code for = 0 value.length - 1: symbol = value(i): ... value.substring(i, 1) ... keep reference original string, in case.)

    ''' <summary>     ''' different url encode implementation since default .net 1 outputs percent encoding in lower case.     ''' while not problem percent encoding spec, used in upper case throughout oauth     ''' </summary>     ''' <param name="value">the value url encode</param>     ''' <returns>returns url encoded string</returns>     public function urlencode(byval value string) string         dim result new stringbuilder()          each symbol char in value             if unreservedchars.indexof(symbol) <> -1                 result.append(symbol)             else                 'some symbols produce > 2 char values system urlencoder must used correct data                 dim hexascw string = string.format("{0:x2}", cint(ascw(symbol)))                 if hexascw.length > 3                     result.append(httputility.urlencode(value.substring(value.indexof(symbol), 1)).toupper())                 else                     result.append("%"c & hexascw)                 end if             end if         next         return result.tostring()     end function 

i've refactored hexascw duplicated expression.

you have 2 ?
answering question in title.
string.indexof(char) point same character char?
documentation yes.

string.indexof method (char)

reports zero-based index of first occurrence of specified unicode character in string.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -