Sign in to follow this  
Followers 0
luddenm

Removing a charcter from the end of a variable.

9 posts in this topic

$Var1 = "C:\"

Func Formatc()
@comspec Format $Var1
endFunc

I want to be able to remove the slash at the end of C:\ so that Var1 = C: in Formatc Function. Thanks :unsure:

I know there is probably a better way to do it but i am a beginner.

Share this post


Link to post
Share on other sites



you can use a basic StringReplace :

$Var1 = "C:\"
$Var1 = StringReplace ( $Var1, ":\", ":")

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Or StringTrimRight()

$Var1 = StringTrimRight($Var1, 1)

:unsure:


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

hi luddenm,

Search the help-file for StringTrimRight(). Example:

$result = StringTrimRight("C:\", 1)
MsgBox(0, "String without rightmost character is:", $result)

Hope this helps :unsure:

-smartee

Share this post


Link to post
Share on other sites

A bit slow guys ! Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Or the StringTrimRight() function:

$Var1 = "C:\"
Formatc($Var1)

Func Formatc($drive)
    MsgBox(0, "Test", "@comspec format " & StringTrimRight($drive, 1))
EndFunc

Or StringLeft() function:

$Var1 = "C:\"
Formatc($Var1)

Func Formatc($drive)
    MsgBox(0, "Test", "@comspec format " & StringLeft($drive, 2))
EndFunc

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Thanks guys, went with the StringTrimRight and worked. :unsure:

Share this post


Link to post
Share on other sites

It will fail if your string is not c:\

In my opinion StringLeft() is the best choice here because it doesn't care about the string behing the 2nd character.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
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
Sign in to follow this  
Followers 0