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

    Extracting parts of a string

    I have a string like the following...

    00009 / Ivory / 3-5

    00009 is the style
    Ivory is the color
    3-5 is the size

    I need to create a Color and a Size formula. I can easily get the style by LEFT({icitem.desc},5) BUT...

    How would I get the color? The size? How would I create a formula that would use the "/" as the delimiter and extract after it?

    As always, any help here is GREATLY appreciated!

  2. #2
    Join Date
    Sep 2004
    Posts
    65

    Re: Extracting parts of a string

    You should be able to use Split({icitem.desc}, "/")[2] to get the color and Split({icitem.desc}, "/")[3] to get the size.

  3. #3
    Join Date
    Oct 2008
    Posts
    3

    Re: Extracting parts of a string

    I get the following error now:

    "A subscript must be between 1 and the size of the array"

    Any ideas?

  4. #4
    Join Date
    Sep 2004
    Posts
    65

    Re: Extracting parts of a string

    Do you have some records that don't have all 3 elements in the string?

    You may be able to try the following for color...
    Code:
    //if Count (Split("00009 / Ivory / 3-5", "/")) >=2 then Split("00009 / Ivory / 3-5", "/")[2] else "Undefined"
    
    if Count (Split({icitem.desc}, "/")) >=2 then Split({icitem.desc}, "/")[2] else "Undefined"
    and this for size...
    Code:
    //if Count (Split("00009 / Ivory / 3-5", "/")) >=3 then Split("00009 / Ivory / 3-5", "/")[3] else "Undefined"
    
    if Count (Split({icitem.desc}, "/")) >=3 then Split({icitem.desc}, "/")[3] else "Undefined"
    Hope this helps
    -Ranthalion

  5. #5
    Join Date
    Jun 2006
    Posts
    38

    Re: Extracting parts of a string

    Mid({icitem.desc}, Instr({icitem.desc}, ' / ') + 3,InStr({icitem.desc}, ' / ') - InStrRev({icitem.desc}, ' / ') - 2)

    Would that work?

  6. #6
    Join Date
    Jun 2006
    Posts
    38

    Talking Re: Extracting parts of a string

    The split function returns an array, not an element of the array.

    Try

    Code:
    StringVar array x
    
    x:=Split({icitem.desc}, ' / ')
    x(1) is the Style
    x(2) is the color
    x(3) is the size

    I believe this should work.

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