Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to find output like this type

suppose my string is -
string = "usernameemail_idpassword";
and after seperate with comma the output will come like

"username,email_id,password"
pls send me some solutions as soon as possible
Posted
Comments
F. Xaver 3-Feb-16 5:23am    
well, we can't help you with that.
how should we know where to place the commas. you provided no reasonable infos for that.

C#
string[] words = string.Split(',');


C#
foreach (string word in words)
	{
	    Console.WriteLine(word);
	}
 
Share this answer
 
v3
Comments
Member 12222029 3-Feb-16 3:33am    
It's not working for dynamic strings
1. You can split (separate) a string into sub-strings when you now the separators chars (spaces, coma, etc), and in that case you should use the string.Split() method like is indicated in "Solution 1" above.

2.But in your case you have a set of concatenated words with no separators between them.
In this case you should provide some rule that could be used for splitting, like in your case all words from the string has the same length (8 chars). So if you have this rule the the solution is the next one:
C#
string input = "usernameemail_idpassword";
int length = 8;
int n = input.Length;
StringBuilder temp = new StringBuilder();
for(int i=0; i< n; i+=length)
{
    if (i > 0)
    {
        //Add the separator.
        temp.Append(",");
    }
    //Split the string using the "fixed length" rule.
    temp.Append(input.Substring(i, length));
}
// Get the result.
string result = temp.ToString();
Console.WriteLine(result);
 
Share this answer
 
v2
Comments
Member 12222029 3-Feb-16 3:34am    
It's not working for dynamic strings
not acceptable
Da-broken-Breakpoint 3-Feb-16 4:23am    
Reason it wont work is there isnt any fixed delimiter from which one could get the position and get the outputs separately. This is why Raul has specified a business rule where in a fixed length can be used. Since "usrnmemail_idpwd" and "usernameemail_idpassword" cannot be split using the same business rule or logic.
Raul Iloc 3-Feb-16 13:55pm    
Thank you for your support comment!
Raul Iloc 3-Feb-16 13:57pm    
There is no solution in your case if you don't have a rule, like "length rule" (from my solution) or something similar.
Member 12222029 4-Feb-16 0:05am    
ya you r absolutely right but I want to do something like this. I want to just confirmed that is it possible or not.

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