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

Parsing a text string in to several variables ...

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

    Parsing a text string in to several variables ...

    I need to read a text file, line by line, and parse each line in to several different variables.

    file.read_line() reads each line but does not preserve the spaces between fields.

    Is there a command that can read each line AND preserve the spaces?

    If not, what commands do you guys think would accomplish the parsing.

    Here is an example line:

    29233643 265672865 ROLIO3107 ROLIO, JOHN $175.00 1518054998 650275504 62308 02/14/2006.

    I can read the line in to a variable called text.

    Then the first number (29233643) is easy to grab and put in to a variable - r.g., id=left(text,8)

    The second number is also easy - e.g., id2=substr(text,10,9)

    These are easy because the first 2 numbers are alsway 8 and 9 characters, respectively, but the next 2 (ROLIO3107 and ROLIO, JOHN) can vary in length.

    So, if the command preserved the spacing, it would be easy - just use substr for every piece of data that I need to extract.

    But if not, does anyone know how to parse the 3rd and 4th fields?

    Gary
    Gary S. Traub, Ph.D.


    #2
    Re: Parsing a text string in to several variables ...

    This is always a fun area of programming, taming the wild text string.

    I would run the string through several phases before ultimately reading the contents. It largely depends on what variation your string might have. Things like will the date always have a zero-padded month and day. But taking that particular string, I would use the word() function to grab all values.

    For the variable "last, first name" area, you can tweak word() to grab the "word" from front to that dollar sign, then sluff off the non-name portion. That works if the dollar sign is constent, and would work even if they tossed in a middle initial and suffix.

    You can read your text file in to memory with file.to_string(). If each line has a crlf on the end, you can then use a loop routine to review each line in turn:

    lst = file.to_string("c:\myfile.txt")
    for each foo in lst
    ..your functions
    next

    If you need real power, look in the help for the "scanner" functions.
    Steve Wood
    See my profile on IADN

    Comment


      #3
      Re: Parsing a text string in to several variables ...

      Gary - I don't have time to model your code, but:

      use w_count() to find the number of words in the string. Looks like you have the same number of words in each string though?

      Use word() to find the nth word in the string.

      Broadly:

      MyVar1 = word(TextString,1)
      MyVar2 = word(TextString,2)
      ....
      -Steve
      sigpic

      Comment


        #4
        Re: Parsing a text string in to several variables ...

        One technique I've used in the past uses the word() function.

        First read the whole file into a variable, then use the word function to parse each line by telling the function that the separator is crlf(). Then, for each line, change the word delimiter to a space.

        You could either store each line in an array, or if there is no other ned for the line, then use the FOR EACH...NEXT to go through each one.

        Pat

        OOPS, I'm way too slow....
        Pat Bremkamp
        MindKicks Consulting

        Comment


          #5
          Re: Parsing a text string in to several variables ...

          Steve, Steve, and Pat,

          Boy, that was easy :D

          Thanks so much - that saved me hours ......

          Gary
          Gary S. Traub, Ph.D.

          Comment


            #6
            Re: Parsing a text string in to several variables ...

            Actually, one more question:

            I used the following to try to extract the name:

            fname=word(text,4,"$")

            but it returns nothing.

            What am I doing wrong?

            Gary
            Gary S. Traub, Ph.D.

            Comment


              #7
              Re: Parsing a text string in to several variables ...

              Originally posted by drgarytraub View Post
              Actually, one more question:

              I used the following to try to extract the name:

              fname=word(text,4,"$")

              but it returns nothing.

              What am I doing wrong?

              Gary
              How many $ are in the text? Sounds like less than 3.
              Al Buchholz
              Bookwood Systems, LTD
              Weekly QReportBuilder Webinars Thursday 1 pm CST

              Occam's Razor - KISS
              Normalize till it hurts - De-normalize till it works.
              Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
              When we triage a problem it is much easier to read sample systems than to read a mind.
              "Make it as simple as possible, but not simpler."
              Albert Einstein

              http://www.iadn.com/images/media/iadn_member.png

              Comment


                #8
                Re: Parsing a text string in to several variables ...

                Just one
                Gary S. Traub, Ph.D.

                Comment


                  #9
                  Re: Parsing a text string in to several variables ...

                  Originally posted by drgarytraub View Post
                  Just one
                  Code:
                  text="29233643 265672865 ROLIO3107 ROLIO, JOHN $175.00 1518054998 650275504 62308 02/14/2006."
                  
                  'Default delimiter is space,comma,decimal point
                  ?word(text,1)
                  = "29233643"
                  
                  ?word(text,2)
                  = "265672865"
                  
                  ?word(text,3)
                  = "ROLIO3107"
                  
                  ?word(text,4)
                  = "ROLIO"
                  
                  ?word(text,5)
                  = "JOHN"
                  
                  ?word(text,6)
                  = "$175"
                  
                  ?word(text,7)
                  = "00"
                  
                  ?word(text,11)
                  = "02/14/2006"
                  
                  'Now change the delimiter to $
                  ?word(text,1,"$")
                  = "29233643 265672865 ROLIO3107 ROLIO, JOHN "
                  
                  ?word(text,2,"$")
                  = "175.00 1518054998 650275504 62308 02/14/2006."
                  
                  ?word(text,3,"$")
                  = ""
                  
                  ?word(text,4,"$")
                  = ""
                  Al Buchholz
                  Bookwood Systems, LTD
                  Weekly QReportBuilder Webinars Thursday 1 pm CST

                  Occam's Razor - KISS
                  Normalize till it hurts - De-normalize till it works.
                  Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
                  When we triage a problem it is much easier to read sample systems than to read a mind.
                  "Make it as simple as possible, but not simpler."
                  Albert Einstein

                  http://www.iadn.com/images/media/iadn_member.png

                  Comment


                    #10
                    Re: Parsing a text string in to several variables ...

                    Hi Al,

                    Thanks for the detailed explanation - very helpful!!!

                    Gary
                    Gary S. Traub, Ph.D.

                    Comment

                    Working...
                    X