String.trim doesn't work

I agree, I’m just testing OP code and it works here.

I just don’t like a thread with title “XYZ doesn’t work” and talk about the docs or better code to do things (sending the message that in fact XYZ is broken) when XYZ is working. That’s all.

maybe the original text is “data-n-head=”
and the trim search for data-n-head= not “data-n-head=”
i mean this quotes

you could output this Pos or look the value at break point.
or check if it is a real minus char

You should inspect your data. If it works sometimes, an not in others, something is not matching. GIGO: Garbage In, Garbage Out. :smile:

I don’t understand how you can write that. It is MyString2 = MyString1.Trim or MyString2 = Trim(MyString1) but what is MyString2 = MyString1.Trim(MyString3)???

It removes the chars in MyString3 from the start and end of MyString1 and stores the result in MyString2.

1 Like

a new feature instead of removing just the space char.

The example in the old doc is:

Var source As String = "<div>Hello World</div>"
Var result As String = source.Trim ("<div>","</div>")      // Returns "Hello World"
2 Likes

Fixing that example would help very much people consulting the docs.

https://tracker.xojo.com/xojoinc/xojo/-/issues/71314 just created.

2 Likes

it’s exaclty why i used trim for :slight_smile:

i was updating to API 2 some old code, where i used trim a lot like this, to remove stuff in html source file, but maybe i shouldn’t ?

i tried to repliquate in a exernal files the problem

var curRemove,curMeta as string
var pos as integer

curMeta =  "data-n-head"+"SBF borrowed $546M from Alameda to fund Robinhood share purchase"

curRemove = "data-n-head="

Pos = curMeta.indexof(curRemove)

if Pos <> -1 then
  curMeta = curMeta.Trim(curRemove) 
  
end if

messagebox (CurMeta)

// shows "SBF borrowed $546M from Alameda to fund Robinhood share purchase"
// so it has removed "data-n-head="

so it worked as i expected, but not as many of you expected it :wink:

ah yes i read the doc, didn’t say that it’s limited to a single character, since i was using it like above and it worked so far, for some times now

so maybe something has changed in the compiler ?
but it still works !

bottom line, i’m now searching all my string.Trim, not sure they work anymore, to replace with string.replace with “”

Your code in this post doesn’t work because you are missing a = on the first line. I get this:
image

I don’t understand what your problem is or what you think your problem is.

What change in the compiler?

Maybe your code on your first post got changed in some way?

The code I posted will show this message:
image

Is this what you want?

sorry i was simplying the code for readability, i deleted = by accident

and i can’t edit my post anymore pfff

my problem is: i was using trim to remove strings, now it doesn’t seem to work like before

yes me neither, i wanted to write trim doesn’t work in some cases, but i barely, even IRL, finishes my sentences, sorry about that, doing too many things same time…

funny thing, while searching trim in my code

i’ve bumped into the example from the doc !!

For me it works like before. Can you create a sample that works in older version of Xojo and it doesn’t work on newer version?

yes but you might not use it to remove complete strings like above

ps : xojo doc has changed :wink:

I’m sorry, English is not my first language. I don’t see any big difference between:
https://docs.xojo.com/String.Trim
and
https://documentation.xojo.com/api/data_types/string.html#string-trim

besides the error for <div>, </div> when they converted the docs to the new documentation.

What about String.ReplaceAll ? From what I see above, it would probably work as you expect.
https://documentation.xojo.com/api/data_types/string.html#string-replaceallbytes

how many trim is there ?? :laughing:
in xol trim is sorted in Text

https://docs.xojo.com/Text.Trim
Page last updated 30 August 2018

https://documentation.xojo.com/api/text/trim.html
doesn’t say deprecated

https://documentation.xojo.com/api/deprecated/text.html#text-trim
say deprecated

I guess the documentation needs some updates.

1 Like