Hello
There,
How can one separate a text into 2 columns (FirstName and LastName).
The only Hint I have is the UpperCase of the second name.
Eg. EdwardJohn I want it to be Edward in one column and John in the second column.
Any help shall be appreciated
Loading

VulpesRank #55 · 29.2K reputationPosted Nov 21, 2012, 11:57 PM EST
steve potts29 reputationPosted Nov 22, 2012, 12:03 AM EST
steve potts29 reputationPosted Nov 22, 2012, 12:13 AM EST
rasul moh64 reputationPosted Nov 22, 2012, 1:00 AM EST
TextBox1.Text.Split();
string fName = string.Empty;
string lName = string.Empty;
string[] words = TextBox1.Text.Split(' ');
if (words.Length >= 3)
{
fName = words[0];
lName = words[1];
}
else
{
fName = words[0];
}
TextBoxF.Text = fName.ToString();
TextBoxL.Text = lName.ToString();......
output display
TextBoxF.Text=Edward and TextBoxL.Text=John
and then write insert query from database , seperate column save the name
Easy method
Edward Munya20 reputationPosted Nov 22, 2012, 2:11 AM EST
Seems to work fine with one values.
But one more thing. data to be split is a big table in sql. How to read it, split it into 2 columns and insert new values in another table with 2 columns i.e First name and LastName.
I am thinking of reading data by datareader to put these values in arrays and insert values in new table using sql command. But how???
steve potts29 reputationPosted Nov 22, 2012, 2:51 AM EST
steve potts29 reputationPosted Nov 22, 2012, 2:57 AM EST
steve potts29 reputationPosted Nov 22, 2012, 3:09 AM EST
foreach (DataRow row in dt.Rows)
{
string rows = string.Format("{0} {1}", row.ItemArray[0], row.ItemArray[1])+ "\n";
textBox1.AppendText(rows.ToString());
}
connection.Close();
Edward Munya20 reputationPosted Nov 22, 2012, 3:22 AM EST
It is working fine. Along the way I came across another issue where names are like in this format;
STEVEPotts
where all FirstName characters are in uppercase and only the first character of the last name is in uppercase.
How to split such text; I want FirstName STEVE Lastname Potts.
Thanks again
steve potts29 reputationPosted Nov 22, 2012, 3:35 AM EST
http://www.cheatography.com/davechild/cheat-sheets/regular-expressions/
VulpesRank #55 · 29.2K reputationPosted Nov 22, 2012, 3:46 AM EST
The output is:
Edward Munya20 reputationPosted Nov 22, 2012, 3:46 AM EST
I think of using a loop and extract all uppercase characters except
the last one. Make this part as Firstname and the remaining part of course shall be the lastname.
Any idea how to do this?
Edward Munya20 reputationPosted Nov 22, 2012, 5:44 AM EST
I think the last challenge I have is to convert object values from the table
retrived by sqldatareader into a string array.
You have used a string array values to split firstname and lastname. I need to convert my values from a database to string array and pass them through the loop as you indicated.
Please any Idea?
Thx in advance.
VulpesRank #55 · 29.2K reputationPosted Nov 22, 2012, 6:51 AM EST
Edward Munya20 reputationPosted Nov 22, 2012, 7:46 PM EST
After days of trying this. You finally showed how to do it.You are a really talented fellow
Thx indeed
Naresh Ch7 reputationPosted Dec 21, 2012, 12:38 AM EST