Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Pulling Characters from a string

Pulling Characters from a string

Pulling Characters from a string

I need helping pulling characters from a prompt.

The prompt:

Enter Product Class Code: (#, #;#, [RETURN]=ALL, E=Exit)

Then Entries:
1.  The Operator can enter EN (Product Class).
2.  The Operator can enter EN;TJ;KI (Multiple Product Classes).

I'm having problem with #2.

I want to pull the Product Classes only.

The number of product classes can change, depending on the entry.

I would like to loop through that string using the ";" as a count to find out how many entries there are.  I will then use those entries for a sql.

Please, the easiest and fastest code would be appricated.

Ken S.

RE: Pulling Characters from a string


Some time ago, I had to parse a string based on a character delimiter.  Appended is the function using your test code.  4GL doesn't do these functions real well since the strings passed are fixed length.

I have a number of string related 4GL functions.  Should I add a FAQ to this forum?



   tmp_string CHAR(20),
   ret_string CHAR(10),

LET cnt = 1
LET tmp_string = "EN;TJ;KI"
# while loop breaks at the 4th loop
WHILE cnt > 0
   CALL parse_str(";", cnt, tmp_string) RETURNING ret_string, cnt


# This function searches string for an instance of char_delim
# starting at position cnt and returns the string ending at the next
# char_delim or the end of string
FUNCTION parse_str(char_delim, cnt, string)
   char_delim CHAR(1),   # character delimiter
   cnt SMALLINT,         # postion in string to start counting
   string CHAR(300),     # string to search
   ret_string CHAR(40),  # string returned
   i,                    # index
   x,                    # counter
   string_len SMALLINT   # string length

   LET string_len = LENGTH(string)

   IF string_len = 0 # got a null string
     RETURN "",0

   IF string[cnt] = char_delim
      LET cnt = cnt + 1 # get off the delimiter
   IF cnt > string_len
   THEN # return when the end of the string is reached
     RETURN "",0

   LET x = 1
   FOR i = cnt TO string_len
      IF string[i] = char_delim
         EXIT FOR
      END IF
      LET ret_string[x] = string[i]  # save a character
      LET x = x + 1

   LET cnt = i # return the positon ended
   RETURN ret_string, cnt

RE: Pulling Characters from a string


Thanks for the response.

That would be a great idea. You guys know more about the tricks of informix than I do at this point in time.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close