Jump to content

StringTrimLeft AND StringTrimRight


Recommended Posts

I have a

$string_variable = "XToday is a new dayX"

And I want to remove the first AND the last letters (both "X"), so my $string_variable will be meaningful ("Today is a new day").

How to do $trimmed = {StringTrimLeft ($string_variable, 1) AND StringTrimRight ($string_variable, 1)}

?

Thanks.

Best regards.

MLMK - my blogging craziness...
Link to comment
Share on other sites

I have a

$string_variable = "XToday is a new dayX"

And I want to remove the first AND the last letters (both "X"), so my $string_variable will be meaningful ("Today is a new day").

How to do $trimmed = {StringTrimLeft ($string_variable, 1) AND StringTrimRight ($string_variable, 1)}

?

Thanks.

Best regards.

$string_variable = "XToday is a new dayX"
$trimmed = StringTrimLeft ($string_variable, 1)
$trimmed = StringTrimRight ($trimmed, 1)
MsgBox (0, "TRIMMED", "Trimed from '" &$string_variable & "' to '"&$trimmed&"'")
Link to comment
Share on other sites

Just for academic interest, you can "nest" functions in AutoIt, which means the input parameter to a function can be a call to another function. So you might start with Bert's working demo:

$string_variable = "XToday is a new dayX"
$trimmed = StringTrimLeft ($string_variable, 1)
$trimmed = StringTrimRight ($trimmed, 1)
MsgBox (0, "TRIMMED", "Trimed from '" &$string_variable & "' to '"&$trimmed&"'")

...and combine the StringTrim functions:

$string_variable = "XToday is a new dayX"
$trimmed = StringTrimRight (StringTrimLeft ($string_variable, 1), 1)
MsgBox (0, "TRIMMED", "Trimed from '" &$string_variable & "' to '"&$trimmed&"'")

...and combine again into the MsgBox (if you don't need the intermediate $trimmed variable for later use):

$string_variable = "XToday is a new dayX"
MsgBox (0, "TRIMMED", "Trimed from '" & $string_variable & "' to '" & StringTrimRight (StringTrimLeft ($string_variable, 1), 1) &"'")

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...