I just can split this string RRS feed

  • Question

  • User311988635 posted

    Hi all

    Maybe i'm missing some thing here i don't know but its sure doing my head.

    Basically users can add keywords to there uploaded images when viewing an image i can get all the keywords as string split them and enter them in a repeater control as hyperlinks. 

    The problems arise when they cut and paste the keywords or i retrieve them from the iptc data.

    The keyword comes out as one long string i think no problem because when entered by hand they end up as one string when retrieved from the database.

    I cant seem to split these keywords but i can the others.

    i use this code

    Dim Array As Array
            Array = strKeywords.Split(", ",";"," ")

    this gives me just the one keyword one long string

    I have tried using the  ChrW(0) ect i have tried replacing spaces with comma then split at comma.

    I then tried splitting at "a" which removed all the a but still left me with one string at Array(0)

    nothing at Array(1)

    Does any one know whats happening here or where i'm going wrong 


    Wednesday, February 14, 2007 5:05 PM

All replies

  • User1335583151 posted

    Hello my friend,

    I have the answer for you.  Make use the following: -

    Dim strKeywords As String = "scott,really;likes london"

    Dim chars() As Char = {", ", ";", " "}

    Dim strArray() As String = strKeywords.Split(chars)


    If you have any problems, please let me know. 

    Kind regards



    Wednesday, February 14, 2007 6:11 PM
  • User311988635 posted

    Sorry mate it didn't work

    I thought it might but no i still get one string.

    The bit i don't understand is when retrieving the keywords from the database they come out as one word no matter how they are entered into the data base.

    But if a user enters the keywords by hand it splits the words nicley. If the keywords have been cut and pasted in or retrieved from iptc data it wont split them at the [space char] it does split them at at say an [a char] ie if i add to your code

    Dim chars() As Char = {",", ";", " ","a"} this works it splits them and keeps them as separate strings. Starnge

    Do you think that maybe if they cut and past the space is getting somehow corrupted.

    You can view what i mean at http://www.raw-stock-images.co.uk on the homepage scroll to latest images open the ciggy butt image witch gets the keywords from iptc data 

    Thanks for your help 

    Wednesday, February 14, 2007 6:37 PM
  • User743145481 posted

    Looking at the HTML, your keywords are separated by a new line and not just a space.  You should just use a regular expression.  Something like "\s*|[,;]*" to split the string.

    // C#
    string []strSplit = System.Text.RegEx.Split(@"my input;string,
    asd", "\\s*|[,;]*");
    ' VB.NET
    ' split up lines to make it less likely to expand forum
    Dim strSplit() As String = System.Text.RegEx.Split(_
                                    "my input;string," + Environment.NewLine + _
                                    "asd", "\s*|[,;]*")

    Hopefully this works for you, let us know otherwise. The regular expression might be better if you use "(\s|[,;])*" but I have not tested either one to be honest.

    On an unrelated note, you should make sure you are Encoding your query string variables before putting them into your links.

    Wednesday, February 14, 2007 10:37 PM
  • User311988635 posted

    Hi pickyh3d,

    Your code didn't work it split every character into single hyperlinks but it got me thinking when you said it was being separated by a new line.

    And when i looked at the query string it would show all keywords as one word. I thought maybe it was the way the iptc data was entered and thats where the problem was. The iptc itemDelimiter was set to vbcrtf i changed this to comma space and sure enough it now splits at the entered comma. I cant remember setting the delimiter to vbcrlf. I should have looked at this earlier.

    The reason i didn't is because in photoshop when you enter your iptc data it puts in a semi colon automatically between keywords so i assumed this is carried across with the iptc data to keep the words separate.  Somewhere these semi colons are dropped and not entered into the database the iptc.itemdelimiter  was then giving them a new line instead of a space. When retrieving the keywords from the database and reading them into the label it was just one word with no spaces or comma and i suppose you cant see new line.

    As for encoding query strings when i first started this site i knew nothing i had a basic knowledge from using the Sinclair spectrum 20 odd years ago. So i built the site and it took over a year i knew that i mustn't put critical paths into query strings so i have only put non critical stuff in the strings in other words it don't think it matter's if they are changed. Encoding of query stings is new to me.

    As the site is now finished i have the time to look into this.

    Thanks to you both for your help 

    Thursday, February 15, 2007 4:59 AM
  • User-1910134229 posted

    hi ,

    You can try arraylist like this code...      

    ArrayList EmailToList = new ArrayList();
            char[] splitter = {','};
            string emailList=txtEmail.Text.Trim().ToString();

    for (int counter = 0; counter < EmailToList.Count; counter++)

    // Do your task here 


    If this post solve your problem mark as answer


    Tuesday, January 5, 2010 6:03 AM
  • User-1910134229 posted
    Hi you can try like this ....
    [] delimiterChars = { ',', ';' };
    string[] delimiterStrs = { "\r\n" };

    string[] name = names.Split(delimiterChars);
    string[] email = emaillist.Split(delimiterStrs, StringSplitOptions.None);

    Tuesday, January 5, 2010 6:50 AM