|
-
November 12th, 2008, 12:16 PM
#1
C# substring type method?
Is there an easy way to get a substring of a string? I am calling a method that returns back an array of values that look similar to:
keys[0] = "All|All";
keys[1] = "Admin|Admin";
keys[2] = "Shop Floor|Shop Floor";
keys[3] = "Development|Development";
keys[4] = "Front Desk|Front Desk";
When I receive the results, I want to break out the results so that All|All becomes All and Admin|Admin becomes Admin. Is there an easy way to get rid of everything after the "|"?
-
November 12th, 2008, 01:00 PM
#2
Re: C# substring type method?
Code:
key[n].Split('|')[0]
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
November 12th, 2008, 01:08 PM
#3
Re: C# substring type method?
Can also do this way... though CPUWizard has more elegant solution 
Code:
string[] q = Regex.Split("All|All", "[|]");
MessageBox.Show(q[1].ToString().Trim());
Last edited by MMH; November 12th, 2008 at 01:12 PM.
Regards,
MMH
Rate my post if you find it usefull. 
-
November 12th, 2008, 01:58 PM
#4
Re: C# substring type method?
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
|