Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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
    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, 04:13 PM.
    There can be only one.

    Comment


      #3
      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".

      Comment


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

        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.

        Comment


          #5
          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, 05:04 PM.
          There can be only one.

          Comment


            #6
            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.

            Comment


              #7
              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"
              Gregg
              https://paiza.io is a great site to test and share sql code

              Comment

              Working...
              X