Skip to content

More explanation for Str\trim #1391

@Scowley4

Description

@Scowley4

Where is the problem?

In the documentation for Str\trim, both in the explanation and the examples.

What is the problem?

The page does not explain what happens if the optional character mask is provided. I think something like:

"If the character mask is provided, all occurrences of characters in $char_mask will be trimmed from beginning and end. Note that order of characters in $char_mask does not matter."

I think it would be nice to add an example "gotcha".

For example:

// POTENTIAL GOTCHA
$s = Str\trim('/user/home/mydocs/', '/user/home/');
// Gives 'ydoc`, when a user may be expecting `mydocs/`

Reference

I've seen this "gotcha" with python s.strip() as well. It appears trim operates the same way.

https://docs.python.org/3/library/stdtypes.html#str.strip

Note

Duplicate language or maybe just a "See the gotcha in Str\trim should probably be added to the other trim functions.


  • Build ID: HHVM=HHVM-4.164.0:HSL=v4.108.1:2024-02-08T13:44:46+0000:1fa47f258c6b68f8ec01899aa82fd6ffa0957109
  • Page requested: /hsl/reference/function/HH.Lib.Str.trim/
  • Page requested at: Mon, 04 Aug 2025 21:13:10 +0000
  • Controller: APIClassPageController

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions