Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having a string say

C#
string strDetail= "My Work,123456,Engineer,10000";



If I split the string using the code below I get exception.

C#
string[] Parameters = new string[10];
Parameters=strDetail.Split(',');


When I display the Splitted string only "My" is shown.

Because a space is used between the words "My" and "Work"

But I want the output as

C#
My Work
123456
Engineer
10000

How to achieve this.
Posted

1 solution

No, you don't.
Try it again:
C#
string strDetail = "My Work,123456,Engineer,10000";
string[] Parameters = strDetail.Split(',');
foreach (string s in Parameters)
    {
    Console.WriteLine(s);
    }


And you will get:
My Work
123456
Engineer
10000
Instead, look at what your program is actually receiving as the strDetail string in the debugger: you aren't getting what you expect, I think.
 
Share this answer
 
Comments
KUMAR619 23-Jul-14 4:36am    
Thanks Sir, you are right the input passed was in wrong format.
Because input was passed as arguments from another EXE.
OriginalGriff 23-Jul-14 4:44am    
You're welcome!

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