|
-
Sep 13th, 2006, 10:45 AM
#1
Thread Starter
Hyperactive Member
[2.0] How to extract a portion of a variable in C#
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
-
Sep 13th, 2006, 11:03 AM
#2
Re: [2.0] How to extract a portion of a variable in C#
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.
Code:
string original = "//xx.com/nathb";
string extracted = original.substring(original.LastIndexOf("/"));
May need a bit of tweaking.
-
Sep 13th, 2006, 05:48 PM
#3
Re: [2.0] How to extract a portion of a variable in C#
That string is a path so you can use the IO.Path class:
Code:
string path = "//xx.com/nathb";
string userName = System.IO.Path.GetFileName(path);
That's what I'd do in VB too.
-
Sep 14th, 2006, 02:01 AM
#4
Re: [2.0] How to extract a portion of a variable in C#
or you could use split function.
-
Sep 14th, 2006, 02:31 AM
#5
Fanatic Member
Re: [2.0] How to extract a portion of a variable in C#
Or regular expressions
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Sep 14th, 2006, 07:55 AM
#6
Re: [2.0] How to extract a portion of a variable in C#
There are four ways to skin string x = "a dead cat";
-
Sep 14th, 2006, 03:25 PM
#7
Re: [2.0] How to extract a portion of a variable in C#
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.
I don't live here any more.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|