CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2004
    Posts
    5

    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

  2. #2
    Join Date
    Dec 2003
    Location
    http://map.search.ch/zuerich.en.html
    Posts
    1,074
    "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.

  3. #3
    Join Date
    Apr 2004
    Posts
    17

    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
  •  





Click Here to Expand Forum to Full Width

Featured