str.split() help

Last post 06-29-2009 5:21 PM by RatheeshC. 4 replies.

Sort Posts:

  • str.split() help

    06-29-2009, 10:12 AM
    • Member
      4 point Member
    • jeffiec
    • Member since 08-22-2007, 12:46 PM
    • Posts 33

     I need to split up a string to get some string data, string like "images/test/89lddmen.jpg".

    there will always be number at the beginning, anywhere between 1 and 5000, the first two characters after the number will always begin with"ld", so i can always look for those two chars to split, only thing is i can get it to work.

    dim mystr as string
    dim strar() as string
    mystr="images/test/89lddmen.jpg"
    strar.split(mystr,'ld')

    expected results would be:
    strar(0)="89"
    strat(1)="lddmen.jpg"

    then need to trim the ".jpg" off the end :D
    dont think im forming it corectly though or not too sure of the overflow.

    thanks in advance. 

  • Re: str.split() help

    06-29-2009, 10:59 AM
    Answer

    string mystr = "images/test/89lddmen.jpg";
            string ImageName = mystr.Substring(mystr.IndexOf("ld"));
            string Id = mystr.Substring(mystr.LastIndexOf("/")+1).Replace(ImageName, "");

    Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
  • Re: str.split() help

    06-29-2009, 1:57 PM
    • Member
      4 point Member
    • jeffiec
    • Member since 08-22-2007, 12:46 PM
    • Posts 33

     works great! thank you,
    now i need to strip the 89 off of "images/featured/89" this could be 1, 2, 3 or even 4 numbers, so the qualifier would be the 2nd "/" ?
    also need to strip ".jpg" off the 2nd string, "." as the qualifier?

    imagename = imagename.Substring(imagename.TrimEnd(".jpg"))
    doesnt seem to work

    thanks again for help so far. :)

     

  • Re: str.split() help

    06-29-2009, 5:00 PM
    • Member
      4 point Member
    • jeffiec
    • Member since 08-22-2007, 12:46 PM
    • Posts 33

    Dim trmst As Char() = {"."c, "j"c, "p"c, "g"c}

    imagename = imagename.TrimEnd(trmst)

    that got the first part working, tryed remove to remove the dir path and got this error.

    id = id.Remove(0, 20)

    Index and count must refer to a location within the string. Parameter name: count

    After searching, it apears that it reads it as empty? how can it be empty?

  • Re: str.split() help

    06-29-2009, 5:21 PM
    • Contributor
      5,624 point Contributor
    • RatheeshC
    • Member since 04-25-2008, 2:05 PM
    • Posts 1,198

    Hi,

    To extract the number from "images/test/89"  try this

    string mystr = "images/test/89";

    string Id = mystr.Substring(mystr.LastIndexOf("/") + 1);

     

    To extract the ".jpg" try this

    mystr = "lddmen.jpg";
    string ext = mystr.Substring( mystr.IndexOf("."));

     

    Thanks

    Thanks
    Ratheesh

    Please mark it as answer if it resolves your issue.
Page 1 of 1 (5 items)