Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friends,

what mean this code

filename = verbs[1].Replace("/", "\\");
            if (filename.IndexOf("?") != -1)
            {
                // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                filename = filename.Substring(0, filename.IndexOf("?"));
            }



exactly
if(filename.IndexOf("?") != -1)


thank you
Posted
Updated 8-Jun-11 1:23am
v2

The IndexOf method returns the position of the given substring inside a string and returns a number. If the substring is not found, it returns -1.

In your case the code inside the if statement will only execute if filename contains the "?" character.

See String.IndexOf()
 
Share this answer
 
Comments
lukeer 8-Jun-11 8:21am    
IIRC, paths are not allowed to contain "?" characters. Therefore the code inside the if statement should never execute.
#realJSOP 8-Jun-11 10:31am    
Whether or not the if condition will be satisfied is not germaine to the question at hand.
This checks for the character/string part in the original string (-1 means that it is not part of the string). Before asking such questions you should try something yourself.
 
Share this answer
 
It means return the position of the first occurance of the '?' character. Really, a simple google search would have told you what the IndexOf method does.

EDIT ====================

Why was this 1-voted. It's the correct freakin' answer.
 
Share this answer
 
v2
Comments
RaviRanjanKr 8-Jun-11 23:14pm    
I am also not able to understand why these answer got platinum downvotes, by the way I voted 5 to your nice and perfect answer.
This method finds the first index of the char argument. It returns -1 if the char was not found.
Take a look C# IndexOf String Examples[^] for more Reference.
 
Share this answer
 
Comments
#realJSOP 8-Jun-11 10:30am    
I dn't know why your answer was 1-voted (although to be fair, your answer was submitted an hour after mine was). I voted your answer up to compensate.
RaviRanjanKr 8-Jun-11 23:12pm    
Thanks John :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900