Click here to Skip to main content
15,906,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
string str='aonent/ram'

how to split this string into three parts like aonnet,/,ram
Please share your answers
Posted

No comments...

How to: Parse Strings Using the Split Method (C# Programming Guide)[^]

[EDIT]
Thank you sisir patro for your comment to my answer.

Regarding OP requirements i would suggest to use RegEx[^] with pattern like this: \W|\w+. It should returns: aonent, /, ram as a matches. Tested on: Rad Software Regular Expression Designer[^].

For further information, please, see: How to: Search Strings Using Regular Expressions (C# Programming Guide)[^]

[/EDIT]
 
Share this answer
 
v4
Comments
[no name] 7-Aug-13 5:52am    
I think we can split the string using the deliminators but here the user had asked for the split of the string with the deliminators. "how to split this string into three parts like aonnet,/,ram ".
Maciej Los 7-Aug-13 7:06am    
Thank you for your comment. See updated answer ;)
Manas Bhardwaj 7-Aug-13 13:58pm    
Yes +5!
Maciej Los 7-Aug-13 14:54pm    
Thank you, Manas ;)
 
Share this answer
 
The more elagent solution would to use regular expression.

Check this link

Regex.Split Method (String, String)[^]

There are plenty of online regular expression parsers available through which you can generate regular expression to correctly split the string. For example a regular expression '\b' could help you split the words that is "aonent" and "arm"


[Edit member="Tadit"]
Link text added to reflect the article title.
[/Edit]
 
Share this answer
 
v2
Use Split to separate parts from a string. If your input is "A B C", split on the space to get an array of: "A" "B" "C".

C#
string s = "there is a cat";
    //
    // Split string on spaces.
    // ... This will separate all the words.
    //
    string[] words = s.Split(' ');
    foreach (string word in words)
    {
        Console.WriteLine(word);
    }



for more detail check following link

C# Split
 
Share this answer
 
You can split it by using following code
C#
string[] SelectedString = "aonnet/ram".Split('/');

check the content of string array....
each string separated by slash will be stored in separate index.
 
Share this answer
 
v2
try this may be help you...
C#
string str="aonent/ram" ;
string[] strsplit = str.Replace("/",",/,").Split(',');
 
Share this answer
 

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