Alpha Video Training
Results 1 to 7 of 7

Thread: Substring Creation, how to find last space before x and space or specific character after x

  1. #1
    Member ahope86's Avatar
    Real Name
    Amanda Hope
    Join Date
    Mar 2017
    Location
    New Hampshire
    Posts
    18

    Default Substring Creation, how to find last space before x and space or specific character after x

    I've been banging my head against a wall and spent a couple hours searching online to try to figure out how to accomplish this with no luck. I am needing to make a cross reference table of customer part numbers to our part number. Since on each order, we enter the customer supplied part number in a note field, we do have a way to extract this data to create the reference table, however I'm struggling with some of the details.

    Previously the script was written to find a string, start there and count out 10 characters. However this does not work in all cases. For instance, the string we are looking for, lets call it "0000" will be present in ALL of the customer part numbers, with the complete part number looking like "0000-00000".

    In this instance that method works, however the customer part number could also look like:
    "xxx-0000-00000" or even "0000-00000XXX", in which case we would be missing the beginning or end of the part number.

    So, I need to be able to find the "0000" and then go back to the last space then forward one to find the starting character, and for the ending character find the "0000" then move forward until I find a space, ., or line return and then go back one to find the ending character of the string. This is what I am having trouble figuring out how to accomplish.

    How exactly do I go about defining start_pos and end_pos as I have explained them?

    note = odn.od_packing_slip_note
    cust_pn = at2("0000",note,1)
    start_pos = cust_pn then go back to last space and forward one
    end_pos = # of characters from the st_pos until the next space, ., or line return


    if cust_pn > 0 then
    xref_no = SUBSTR(note,st_pos,end_pos)
    end if

  2. #2
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Substring Creation, how to find last space before x and space or specific character after x

    You are probably going to have to build your own custom function. You mention "xxx-0000-00000" or even "0000-00000XXX". Should the second example be "0000-00000-XXX"? Do the X's represent characters or can they be digits as well?

    Or maybe not. Will this work?

    Code:
    note =  "0000-000000"
    ? ltrim(regex_merge(note,"[a-z]","","SI"),"-")
    = "0000-00000"
    note =  "XXX-0000-000000"
    ? ltrim(regex_merge(note,"[a-z]","","SI"),"-")
    = "0000-00000"
    note = "0000-00000XXX"
    ? ltrim(regex_merge(note,"[a-z]","","SI"),"-")
    = "0000-00000"
    Last edited by Stan Mathews; 05-17-2018 at 05:13 PM.
    There can be only one.

  3. #3
    Member ahope86's Avatar
    Real Name
    Amanda Hope
    Join Date
    Mar 2017
    Location
    New Hampshire
    Posts
    18

    Default Re: Substring Creation, how to find last space before x and space or specific character after x

    0's represent numbers, X's represent characters. In the event that the characters are appended to the end, there would be no "-" to separate them (i.e., no, I did not mean "0000-00000-XXX").

    The number of characters will always be the same and always be in the "0000-00000" format, its just a matter of there may or may not be "XXX-" before them, and may or may not be "XXX" after them.

    If it helps, the first four characters of the number string are always the same (e.g., "1234"). Every part number will have the first four characters of the number string be "1234".

  4. #4
    Member ahope86's Avatar
    Real Name
    Amanda Hope
    Join Date
    Mar 2017
    Location
    New Hampshire
    Posts
    18

    Default Re: Substring Creation, how to find last space before x and space or specific character after x

    Quote Originally Posted by Stan Mathews View Post
    .......

    Or maybe not. Will this work?

    Code:
    note =  "0000-000000"
    ? ltrim(regex_merge(note,"[a-z]","","SI"),"-")
    = "0000-00000"
    note =  "XXX-0000-000000"
    ? ltrim(regex_merge(note,"[a-z]","","SI"),"-")
    = "0000-00000"
    note = "0000-00000XXX"
    ? ltrim(regex_merge(note,"[a-z]","","SI"),"-")
    = "0000-00000"
    This appears to be doing what we already have, which is extracting only the numeric string. We need to be able to pull the characters before and after the number string as well if they exist.

  5. #5
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Substring Creation, how to find last space before x and space or specific character after x

    Ok, this?

    Code:
    note = "abc xyz-0000-00000, next part" + crlf()+" test"
    note = strtran(keywords(note)," ",crlf())
    keynote = *for_each(wd,wd,note,"-" $ wd)
    ? keynote
    = xyz-0000-00000
    
    note = "abcdef. 0000-00000, next part" + crlf()+" test again"
    note = strtran(keywords(note)," ",crlf())
    keynote = *for_each(wd,wd,note,"-" $ wd)
    ? keynote
    = 0000-00000
    
    note = "abcdef, 0000-00000mmm. another part." + crlf()+" test third time"
    note = strtran(keywords(note)," ",crlf())
    keynote = *for_each(wd,wd,note,"-" $ wd)
    ? keynote
    = 0000-00000mmm
    Which would serve as the basis for your custom function.

    Or you could nest the expressions.

    Code:
    note = "nested test, 0000-00000mmm. another part." + crlf()+" test third time"
    keynote = *for_each(wd,wd, strtran(keywords(note)," ",crlf()),"-" $ wd)
    ? keynote
    = 0000-00000mmm
    Just noticed that would fail to return the proper value if there are other dashes in the note.

    Code:
    note = "nested-test, 0000-00000mmm. another part." + crlf()+" test third time"
    keynote = *for_each(wd,wd, strtran(keywords(note)," ",crlf()),"-" $ wd .and. (isnumber(word(wd,1,"-")) .or. isnumber(word(wd,2,"-") ) ))
    ? keynote
    = 0000-00000mmm
    note = "nested-test, zzz-0000-00000. another part." + crlf()+" test-third time"
    keynote = *for_each(wd,wd, strtran(keywords(note)," ",crlf()),"-" $ wd .and. (isnumber(word(wd,1,"-")) .or. isnumber(word(wd,2,"-") ) ))
    ? keynote
    = zzz-0000-00000
    Last edited by Stan Mathews; 05-17-2018 at 06:04 PM.
    There can be only one.

  6. #6
    Member ahope86's Avatar
    Real Name
    Amanda Hope
    Join Date
    Mar 2017
    Location
    New Hampshire
    Posts
    18

    Default Re: Substring Creation, how to find last space before x and space or specific character after x

    Thank you so much.

    From what I can see after running a few tests using our actual data, this is exactly what we need.

    I resolved the issue with returning other dashes in the note field by replacing it with the portion of numbers we know will always be present within the part number.

  7. #7
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,393

    Default Re: Substring Creation, how to find last space before x and space or specific character after x

    Hi Amanda,

    I know I'm a bit late, but would
    Code:
    cust_pn= if(occurs("-",note)=2,substr(note,at("-",note,2)+1,5),substr(note,6,5))
    work?

    Here are a few examples :
    note = "0000-12345xxx"
    cust_pn= if(occurs("-",note)=2,substr(note,at("-",note,2)+1,5),substr(note,6,5))
    ?cust_pn
    = "12345"
    note = "xxx-0000-54321"
    cust_pn=if(occurs("-",note)=2,substr(note,at("-",note,2)+1,5),substr(note,6,5))
    ?cust_pn
    = "54321"
    note = "0000-34567"
    cust_pn= if(occurs("-",note)=2,substr(note,at("-",note,2)+1,5),substr(note,6,5))
    ?cust_pn
    = "34567"

Similar Threads

  1. update to yield a space character
    By John Cunradi in forum Alpha Five Version 11 - Desktop Applications
    Replies: 32
    Last Post: 06-18-2014, 04:21 AM
  2. Opening up a dialog2 from a grid leave an extra space in the character fields
    By Islip in forum Application Server Version 11 - Web/Browser Applications
    Replies: 1
    Last Post: 04-15-2012, 06:50 AM
  3. how to remove "space" character from my string?
    By Ken Tjia in forum Alpha Five Version 9 - Desktop Applications
    Replies: 3
    Last Post: 12-24-2008, 04:16 PM
  4. ASCII Character Code For Space
    By Louis Nickerson in forum Alpha Five Version 5
    Replies: 5
    Last Post: 12-13-2002, 07:56 PM
  5. Need direction with Alt-Space & Space Key
    By Coyndigger in forum Alpha Five Version 4
    Replies: 5
    Last Post: 11-27-2000, 03:20 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •