Post Reply 
Another question from a newbie
10-25-2019, 02:21 AM
Post: #1
Another question from a newbie
Please look at behavior described below, and tell me whether it's a bug, or I am doing something wrong.
The User's Manual defines behavior of RIGHT as follows:
Returns the last n characters of string str. If n <= 0, returns empty string. If n > DIM(str), returns str
Example: RIGHT("MOMOGUMBO",5) returns "GUMBO"

The attached example clearly shows that the character pointed by the argument is included in the resulting string. Thus, if we point to the last character of the string, we should get the last character of the string as a result. (Technically it will be a string consisting of one character, but let's use the name "character" to avoid confusing input and output strings.)
Please run the following program:
#pragma mode( separator(.,;) integer(h64) )


  LOCAL sString :="12D";

  // verify indices

  // verifiy length

  // attempt extracting substrings
  PRINT(RIGHT(sString,3));  // should return "D", but returns "12D
  PRINT(MID(sString,3,1));  // should return "D", and it does


The result will be:


(Run on the simulator.)
In other words, if the RIGHT command is used, and the pointer points to the last character in the string, HPP "thinks" that it points beyond the string, and returns entire string rather than one character.

Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
Another question from a newbie - DrDarius - 10-25-2019 02:21 AM

User(s) browsing this thread: 1 Guest(s)