In trim what is stringvariable

In the LR under Trim
https://documentation.xojo.com/api/data_types/string.html.Trim
there is mention of StringVariable without an example without using SourceString

result = stringVariable.Trim

I think that should be

result = SourceString.Trim

If I am correct, please say so.

At any rate, how does one use stringVariable?

Can I trim off the end a file separator “/” ?

I guess another reason I am confused is in TrimLeft there is no mention of SourceString.

You are correct. I have fixed the docs.

Trim removes leading and trailing whitespace from a String. I’m not clear on what you’re doing but I imagine you’re looking for Replace. See: https://documentation.xojo.com/api/deprecated/replace.html Note that Replace removes the first occurrence of a character so you may also need to use it conjunction with Right https://documentation.xojo.com/api/data_types/string.html#string-right

Sorry for not posting my edit.

Nope. It really was “Can I use this instead of Replace?”

Thanks for fixing it.

So, now

result = " whatever ".Trim

is finally implemented?

Until yesterday we were forced to do things like:

Var stringVariable As String = " whatever "
result = stringVariable.Trim

This is the LR for Trim:
https://documentation.xojo.com/api/text/trim.html

String.Trim page has an extra row on the Table, it should only show ‘result’ and ‘stringVariable’. You can’t use sourceString because sourceString is something like " this is the source " when a sourceVariable you need to do:

Var myString As String = " this is the string variable "
myString = myString.Trim // the result is "this is the string variable"

Note: I was on the phone when I started typing here. I disagree with Gavin’s edit. SourceString.Trim I expect something like this to work:

result = (" this is the string variable ").Trim

Yes, the example on the page was also wrong. It’s now fixed as well.

1 Like

FWIW, I wish we could do that. Is there a Feedback case you’re aware of? It’s not an easy one to search for.

The lack of it and more, months ago were extensively discussed. I think that the most vocal one, and that opened a FR, was Norman.

Naming a variable ‘source’ doesn’t make it sourceString but stringVariable.

I think these edits are different that information posted on other docs, making that confusing to the user learning Xojo.

result = Trim(sourceString) is clear that it refers to Trim(" this is a test ")
result = stringVariable.Trim is clear that it refers to a Var named stringVariable

If you changed the table and example for String.Trim, then you will need to change Trim, String.TrimLeft and String.TrimRight to match the information and be consistent.

Maybe a constant can be used as source too.

its still private to testers despite several 4 requests to make it public

<https://xojo.com/issue/56629>

1 Like

I am happy with the edits, since they are no longer confusing.
I apologize for not posting this in testers. I turned deprecation on and this popped up.
Since I had just analyzed it and it didn’t show, etc, etc.

I am not happy with the edits, they are different than what Xojo used for Trim, String.TrimLeft and String.TrimRight that will cause confusion to users.

For me ‘source’ is not a ‘variable’ even if we name that source and you can review the docs and in many places you can see that ‘source’ is reference to actual source and not the variable that holds that source.

For example, this is for String.BeginsWith:

I think is easier to edit just String.Trim to follow the other String docs, than to change most of String docs to match the String.Trim edit.

For the dot notation version of Trim to work you MUST use either a variable or constant like

   var stringVariable as string = " 123 "
   var result as string
   result  = stringVariable.Trim() // <<<<<<<<

or

   const stringVariable as string = " 123 "
   var result as string
   result  = stringVariable.Trim() // <<<<<<<<

dot notation can ONLY can be applied to “variables”

You CANNOT use it like

    var result as string
   result  = "123".Trim() // <<<<<<<<

“123” is NOT a variable - it is a literal

I’ve changed the syntax section back to using “stringVariable” because that is clearer and matches other pages.

Thank you Norman, I understand that.

What I don’t understand is that some String docs mention source, other sourceVariable, other sourceString and some others stringVariable.

Edit: Thank you @Paul_Lefebvre

This sounds unintentional. A Feedback case with page details would be the best way to make sure someone can look into this.