tags:

views:

125

answers:

3

Hello friend

I have code name and surname put into same string with coma in the middle ,as "JohnSmith"

I need to insert into database to separate

Can you show me how to code that please.

Thanks

vijay

+6  A: 

Presumably your asking how to split up a single string where the names are seperated by a comma ','

If that's the case, you can split a string using the Split(char x) method. Then you can use each part what ever way you want.

string x = "John,Smith";

string [] parts = x.Split(',');


if(parts.Length == 2)
{
   string firstName = parts[0];
   string secondName = parts[1];
}

Something like that.

Eoin Campbell
-1 for actually responding with code to "Can you give me code for that."
fig
+1 for a clear and concise answer.
Preet Sangha
@Eoin, I have some code I need you to write asap. Sending it now.
fig
@Eoin, jumping in and writing code in my opinion is not the best way to let the OP learn. Talk them through the solution and let them write it themselves.
Helen Neely
Come to think of it, I think @Preet should have helped the OP ;)
Helen Neely
hahahahhahahhahahahhahahha
Preet Sangha
+2  A: 

Vijay, how about at least trying to google stuff like this by yourself? As in "C# split string"? Hundreds of decent results come up. Heck, there are tons of these examples on SO as well.

Other people can't do your work for you, so how about actually putting in some effort into learning process instead of relying on others to do mundane things for you?

VexXtreme
+1. Though I guess if others want to do the work for the lazy-inclined, who are we to argue? ;)
fig
A: 

This is easy in most cases, but in a production environment the edge cases kill you. I like the string.split answer, but the incredible variation in how names are formated means more thinking and more code.

Mark W