## What does this mean?

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Guest

### What does this mean?

What does LTRIM\$ , RTRIM\$, and STR\$ mean?
example...LEFT\$(LTRIM\$(RTRIM\$(STR\$(q))), 1)
What would that do?

{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

LTRIM cuts off all left spaces. RTRIM cuts off all right spaces EG

Code: Select all

``PRINT LTRIM\$(RTRIM\$("     I have extra spaces!             "));``
Would ouput "I have extra spaces!". As for STR\$, I dunno off hand. You can look it up.

Kyle
Veteran
Posts: 107
Joined: Thu Apr 14, 2005 2:41 pm
Converts a variable into a string. Adds a leading space for signing (+/-)

Code: Select all

``````string\$="Test "+LTRIM\$(STR\$(123))
PRINT string\$
``````

Xerol
Veteran
Posts: 81
Joined: Tue Jan 04, 2005 6:27 pm
Location: Timonium, MD
Contact:
Kylemc wrote:Converts a variable into a string. Adds a leading space for signing (+/-)

Code: Select all

``````string\$="Test "+LTRIM\$(STR\$(123))
PRINT string\$
``````
Except string is a reserved keyword and that code would never run

Xerol's Music - Updated Regularly!

Kyle
Veteran
Posts: 107
Joined: Thu Apr 14, 2005 2:41 pm
You get the idea.

Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

### Re: What does this mean?

Anonymous wrote:What does LTRIM\$ , RTRIM\$, and STR\$ mean?
example...LEFT\$(LTRIM\$(RTRIM\$(STR\$(q))), 1)
What would that do?
LTRIM\$ trims off wightspaces(or spaces) left of a string:

Code: Select all

``````String = "     Hello     "

NewString = LTRIM\$(String)

NewString = "Hello    "``````
RTRIM\$ does the same just for the right side:

Code: Select all

``NewString = "    Hello"``
STR\$ turns a numerical variable to a string.

Code: Select all

``````Var = 100

String = STR\$(Var)

String = "100"``````
As for the code:

Code: Select all

``````q = 200

PRINT LEFT\$(LTRIM\$(RTRIM\$(STR\$(q))), 1)``````
Output is: 2

-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico
Let me walk you through Ratt's example, step by step as it evaluates the statement.

Code: Select all

``````q = 200

PRINT LEFT\$(LTRIM\$(RTRIM\$(STR\$(q))), 1)``````
1. It takes the STR\$ of 200, which gives us a string of 4 characters, a space and 200.

2. Next it does the RTRIM\$ which doesn't do anything because we have no trailing spaces. So we still have a space and 200.
3. Now it does the LTRIM\$, which removes the leading space. We now have 3 characters, 200.

4. Now it does the LEFT\$ on these 3 characters grabbing only the first character as specified by the ",1". So, the final result is 2.

It performs these functions in that order because, in the order of the parenthesis, each function needs a value or a string on which to operate. The STR\$ goes first since it has the value of q to work with. Then the RTRIM\$ works on the string result of the STR\$, and so on.
*****
If you are behind me, follow.
If you are not doing anything,
Get out of the way.

Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:
I was hoping to spark creativity to figure why it does it.... But you are probaly right to explian it for him, it is rather a tricky code being all in one line...
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)

Guest
Thanks. You all helped me out a lot.