BASIC

Author Topic: LTRIM$ and TRIM$ Possible Bug?  (Read 2215 times)

Offline aroldo

  • Mr. Polyvector
  • ***
  • Posts: 143
    • View Profile
    • APD Consulting, Inc.
LTRIM$ and TRIM$ Possible Bug?
« 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[","")
[a http://apd-games.com/][img http://apd-games.com/images/APDGames135.png][/a]
MacBook Pro OS X El Capitan
XCode Version 7
iPhone 6 running  iOS 9
iPad Mini running  iOS 7.1
Galaxy S5
Dell Latitude Windows 8 Enterprise
Palm Pre, Palm Pre2

MrTAToad

  • Guest
Re: LTRIM$ and TRIM$ Possible Bug?
« Reply #1 on: 2013-Apr-04 »
Yes, it is - bit of a slight boo-boo there :)

Offline hardyx

  • Community Developer
  • Dr. Type
  • ******
  • Posts: 491
    • View Profile
Re: LTRIM$ and TRIM$ Possible Bug?
« Reply #2 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.

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
Re: LTRIM$ and TRIM$ Possible Bug?
« Reply #3 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 :)

Offline aroldo

  • Mr. Polyvector
  • ***
  • Posts: 143
    • View Profile
    • APD Consulting, Inc.
Re: LTRIM$ and TRIM$ Possible Bug?
« Reply #4 on: 2013-Apr-05 »
 :nw: Thanks Everyone,

Using the REPLACE$  solves my problem.
[a http://apd-games.com/][img http://apd-games.com/images/APDGames135.png][/a]
MacBook Pro OS X El Capitan
XCode Version 7
iPhone 6 running  iOS 9
iPad Mini running  iOS 7.1
Galaxy S5
Dell Latitude Windows 8 Enterprise
Palm Pre, Palm Pre2