Its quite easy in VB (Instr function).
I have username stored in a string variable. the content of the variable is "//xx.com/nathb". I would like to extract only "nathb" portion . How can I do that in C#?
thanks
Printable View
Its quite easy in VB (Instr function).
I have username stored in a string variable. the content of the variable is "//xx.com/nathb". I would like to extract only "nathb" portion . How can I do that in C#?
thanks
There are many string manipulation functions in .NET: .Substring, .IndexOf(), etc. which you can use to get what you need. In your case, you appear to want the text from the string after the last forward-slash.
May need a bit of tweaking.Code:string original = "//xx.com/nathb";
string extracted = original.substring(original.LastIndexOf("/"));
That string is a path so you can use the IO.Path class:That's what I'd do in VB too.Code:string path = "//xx.com/nathb";
string userName = System.IO.Path.GetFileName(path);
or you could use split function.
Or regular expressions :D
There are four ways to skin string x = "a dead cat";
Serialize the dead cat to a memory stream, move the stream position to one layer below the Skin object and then deserialize again. Optionally Deserialize the skin at a later point if needed.