Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use the trim character_mask 1

Status
Not open for further replies.

Sam050507

Programmer
Sep 13, 2005
18
0
0
US
Hi,

Stupid question.

When I'm trimming strings, what is the use of the character_mask option?

I've Googled, but can't find a good example.

For instance, can I trim the ".00" part of 123.00 using that option?

Thanks
 
For instance, can I trim the ".00" part of 123.00 using that option?

answer: yes, but i would not recommend it.

the charmask is a list of characters that get deleted if they are at the left or right of a string (depending on which of trim, ltrim and rtrim you use).

so
Code:
echo rtrim ("123.00", "0.");
will give you
Code:
 123

but
Code:
rtrim ("123.00.....", "0.");
will also yield the same result.

if you are looking to format numbers, use printf (or its variants) or number_format

i tend to use the trim functions for cleaning user input and for getting rid of trailing commas in assembled sql clauses.
 
I don't know why I couldn't figure that out.

Thanks very much, jpadie.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top