GLBasic forum

Main forum => Bug Reports => Topic started by: aroldo on 2013-Apr-04

Title: LTRIM$ and TRIM$ Possible Bug?
Post by: aroldo on 2013-Apr-04
GLB Team,

I am using LTRIM$ to remove some tags from a text string.
For some odd reason LTRIM$ or TRIM$ is removing the first character after the text it is trimming.
I tried this code in GLB V 11.261 and GLB V 10.283 the result is the same.

Here is the code used:

Code (glbasic) Select
tempmsg$ = LTRIM$(msg$ ,"<![CDATA[")

Here are the input message and the message after the trimming:

msg$: <![CDATA[The 33 directors of the 500 Festival received their Indianapolis 500 Chevrolet Camaros in a ceremony Wednesday at the Indianapolis Motor Speedway, a longtime tradition leading into the Month of May and ?The Greatest Spectacle in Racing.?]]>

tempmsg$: he 33 directors of the 500 Festival received their Indianapolis 500 Chevrolet Camaros in a ceremony Wednesday at the Indianapolis Motor Speedway, a longtime tradition leading into the Month of May and ?The Greatest Spectacle in Racing.?]]>

For now I resolve the issue using the replace$ command:

Code (glbasic) Select
tempmsg$ = REPLACE$(tempmsg$ ,"<![CDATA[","")
Title: Re: LTRIM$ and TRIM$ Possible Bug?
Post by: MrTAToad on 2013-Apr-04
Yes, it is - bit of a slight boo-boo there :)
Title: Re: LTRIM$ and TRIM$ Possible Bug?
Post by: hardyx on 2013-Apr-04
The result is correct, because LTRIM$ deletes *all the occurences* of the characters in trim$ parameter from beggining of the source string. Normally you use this functions to remove spaces or other symbols. In your example, deletes the first "T" because "T" is a character you want to delete.

Example:
a$ = LTRIM$("H+Hello", "H+")

The result is "ello", because the beggining contains "H+H", both deleted.
Title: Re: LTRIM$ and TRIM$ Possible Bug?
Post by: Moru on 2013-Apr-04
Results as expected, TRIM$ is not used that way. TRIM$ is made for removing any number of leading/trailing characters in a string. For example line-breaks, spaces, tabs and so on, to get a clean string with only the data.

If you want to remove a certain word, you need to make your own function to remove it I'm afraid :-)

Edit: Eh, somehow I totally missed your post, hardyx. Sorry for the double info :)
Title: Re: LTRIM$ and TRIM$ Possible Bug?
Post by: aroldo on 2013-Apr-05
 :nw: Thanks Everyone,

Using the REPLACE$  solves my problem.