G
Guest
Hi!
I need to parse some text in a rich text box and store it in an array, each
item of which will be stored in a database table as a separate record.
For. eg If the user enters this text:
We, \\parents, invite you
for the wedding of our son, \\groom
on \\date.
Then I need to parse this text so that it is stored in the array as:
We,
\\parents,
invite you
for the wedding of our son,
\\groom
on
\\date.
Using the split method I am able to split the text but I lose the slashes.
This is the code I have working now:
string[] lines = new string[50];
lines = textToParse.Split("\r\n".ToCharArray());
ArrayList linesList = new ArrayList();
string [] splitLines = new string[50];
for(int i = 0; i < lines.Length; i++)
{
if(lines.ToString().IndexOf("\\\\") >= 0)
{
splitLines = lines.ToString().Split("\\\\".ToCharArray());
for(int j = 0; j < splitLines.Length; j++)
{
linesList.Add(splitLines[j]);
}
}
else
{
linesList.Add(lines);
}
}
StringBuilder builder = new StringBuilder();
for(int i = 0; i < linesList.Count; i++)
{
builder.Append(linesList.ToString());
builder.Replace("\n","",builder.Length - 1, 1);
builder.Append("\n");
}
builder.Remove(builder.Length - 1, 1);
I realize this is not the best way to do it, so I need some help/suggestions
on how to handle this scenario.
Thanks for your time.
Regards,
Kumar
I need to parse some text in a rich text box and store it in an array, each
item of which will be stored in a database table as a separate record.
For. eg If the user enters this text:
We, \\parents, invite you
for the wedding of our son, \\groom
on \\date.
Then I need to parse this text so that it is stored in the array as:
We,
\\parents,
invite you
for the wedding of our son,
\\groom
on
\\date.
Using the split method I am able to split the text but I lose the slashes.
This is the code I have working now:
string[] lines = new string[50];
lines = textToParse.Split("\r\n".ToCharArray());
ArrayList linesList = new ArrayList();
string [] splitLines = new string[50];
for(int i = 0; i < lines.Length; i++)
{
if(lines.ToString().IndexOf("\\\\") >= 0)
{
splitLines = lines.ToString().Split("\\\\".ToCharArray());
for(int j = 0; j < splitLines.Length; j++)
{
linesList.Add(splitLines[j]);
}
}
else
{
linesList.Add(lines);
}
}
StringBuilder builder = new StringBuilder();
for(int i = 0; i < linesList.Count; i++)
{
builder.Append(linesList.ToString());
builder.Replace("\n","",builder.Length - 1, 1);
builder.Append("\n");
}
builder.Remove(builder.Length - 1, 1);
I realize this is not the best way to do it, so I need some help/suggestions
on how to handle this scenario.
Thanks for your time.
Regards,
Kumar