Jump to content



Photo

New string TRIM() functions


  • Please log in to reply
7 replies to this topic

#1 blitzer99

blitzer99

    Wayfarer

  • Active Members
  • Pip
  • 52 posts

Posted 31 July 2005 - 05:53 AM

My thanks to the guys on my forum topic "Enhancement to string TRIM functions" who provided the inspiration (and a lot of the code) :) for four new string TRIM() functions: _LTRIM() _RTRIM(), _ALLTRIM() and _TRIM().

These functions trim unwanted characters from the left, right or both ends of a character string. The default characters trimmed are spaces but more than one contiguous character can be trimmed it once. For example back slashes and spaces my be trimmed together.

The functions that achieve this result are included in the attached file along with installation instructions, reproduced below.

==================================================================
Purpose: Implements new functions _RTRIM(), _LTRIM(), _ALLTRIM(), _TRIM()

To implement functions equivalent to the old dBase functions that removed spaces
from the, respectively, right, left and both left and right of a character string.
The function _TRIM() is equivalent to _RTRIM() and is provided for consistency with
the old dBase standard.

These four functions remove contiguous characters from the left and/or right of a character string
but not those that are within the string. For example _RTRIM("Mary had a little lamb ")
will become "Mary had a little lamb" - the spaces inside the string are not removed.

Syntax: ResultString = <FunctionName>( string1, string2 )

<FunctionName> as above: _RTRIM(), _LTRIM(), _ALLTRIM(), _TRIM()
string1 is the character string to examine.
string2 is a list of the characters to be examined for; if omitted it defaults to the standard space character, chr(32).
ResultString is the string returned by the function with all characters in string2 trimmed from the left and/or right
of string1.

If string2 = "%%whs%%" all white space characters will be trimmed from string1.
Whitespace includes Chr(9) thru Chr(13) which are HorizontalTab, LineFeed, VerticalTab, FormFeed, and arriageReturn.
Whitespace also includes the standard space character.

ResultString will be shorter than string1 by an amount equal to the number of characters trimmed from string1.

These functions are not case sensitive, e.g. "m" in string2 will trim both "M" and "m" from string1.

On any error condition ResultString will be equal to string1.

Examples: _RTRIM("Mary had a little lamb ") -> "Mary had a little lamb"
_RTRIM("Mary had a little giraffe xyxyxyz", "xyz") -> "Mary had a little giraffe " (note space at end has not been removed).
_RTRIM("Mary had a little giraffe xyxyxyz", " xyz") -> "Mary had a little giraffe" (now the same space has been removed because
a space is now included in string2).
_RTRIM("Mary had a little giraffe xyxbyxyz", "xyz") -> "Mary had a little giraffe xyxb" (only the x, y and z following the "b"
will be removed because the "b" is not in string2.

To use: 1. Copy this script to the "Include" folder under the AutoIt programs folder.
(for example: c:\program files\autoit3\include\myfunctions.au3 )
2. In your Autoit3 script have following statement:
#include <myfunctions.au3>
3. "myfunctions" can be renamed to anything you want.

Disclaimer: Thoroughly tested and debugged, but use entirely at your own risk.
Usage automatically acknowledges acceptance of this condition.

Attached Files


  • IgImAx likes this
Computers don't solve problems, they just rearrange them.New string TRIM() functions for AutoIt3





#2 ModemJunki

ModemJunki

    Wayfarer

  • Active Members
  • Pip
  • 52 posts

Posted 07 August 2009 - 02:58 PM

164 downloads and not one reply?

Thanks for this, it makes easy work of cleaning up dirty strings! >_<

#3 dantay9

dantay9

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 834 posts

Posted 07 August 2009 - 05:45 PM

There isn't much to say. They work. They can be useful. Good job.
"Failure is not an option -- it comes packaged with Windows" Gecko Web Browser, Yahtzee!, Toolbar Launcher (like RocketDock)Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI Triangle Solver, TCP File Transfer, Valuater's Autoit WrappersOOP In AutoItUsing Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com

#4 blitzkrg

blitzkrg

    Polymath

  • Active Members
  • PipPipPipPip
  • 232 posts

Posted 07 August 2009 - 07:10 PM

Thanks!!

#5 dixonpete

dixonpete

    Seeker

  • Active Members
  • 27 posts

Posted 10 October 2011 - 03:51 PM

A belated thx!!

#6 Myicq

Myicq

    Prodigy

  • Active Members
  • PipPipPip
  • 167 posts

Posted 14 December 2011 - 02:05 PM

Perfect :)

Thank you!

#7 john7a8

john7a8

    Seeker

  • Active Members
  • 7 posts

Posted 03 May 2012 - 02:01 PM

Another happy dl'er - Excellent Job!!! Thanks ;)

#8 BjornA

BjornA

    Seeker

  • Normal Members
  • 4 posts

Posted 21 May 2012 - 08:19 AM

Thank you ! I was just looking for this function in AutoIt ;)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users