|
-
April 21st, 2004, 12:13 PM
#1
Problem in using Split() with memo field type as the string
I use the split method in C# to break the text when there is a string "<br>". The text comes from database access, the field type is a Memo type instead of Text type. The result that I got is incorrect
(my code example)
string textFromDataBase = "Welcome to ABC corporation in California<br>"
string[] rows = textFromDataBase.Split("<br>".ToCharArray());
However, when I change the database field from Memo to Text type, I get the correct result using the same split method. I am very confuse. FYI, Using the debugger, I see the same string value. I do not know how to solve this issue. At this time, I can not change the DB field from Memo to Text type since I need to store a very long string, more than 255 chars. Please Help me!
Greatly Appreciated for any feedbacks! I am very lost on this one.
Thanks a bunch,
Franky
-
April 22nd, 2004, 02:09 AM
#2
"Split" does not split strings that have "multiple character delimiters" ie. It assumes that each field in the string is delimited by a single character. The character array simply means that the delimiter can vary in the string.
Code:
// Split the string into four words.
string[] words = "This.is;a'test".Split(".;'".ToCharArray());
So, using "<br>" with "Welcome to ABC corporation in California<br>" will result in "r" in particular being used to split it up.
-
April 22nd, 2004, 04:00 AM
#3
Split
Try this little function.
Code:
public string[] Split(string Value,string SplitBy)
{
ArrayList al = new ArrayList();
string sLine = "";
int i = Value.IndexOf(SplitBy,0);
string sStrLeft = Value;
while (i > -1)
{
sLine = sStrLeft.Substring(0,i);
sStrLeft = sStrLeft.Substring(i + SplitBy.Length);
al.Add(sLine);
i = sStrLeft.IndexOf(SplitBy,0);
}
al.Add(sStrLeft);
return (string[])al.ToArray(typeof(string));
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|