Jump to content
Sign in to follow this  
TuMiM

stringtrim

Recommended Posts

TuMiM

I know this is probably easy but I can't figure out the easiest way to do it. If i have a string that comes from a fileopendialog that looks like this \\172.28.206.7\Bservices\LST\AB\file.txt and I need to get only the last directory name so AB in this instance. how can i extract that out keeping in mind that that AB can be other directories named other things.

Share this post


Link to post
Share on other sites
JohnOne

Well regexp would do it, but so will stringsplit

example

$string = "\\172.28.206.7\Bservices\LST\AB\file.txt"

$split = StringSplit($string,"\",3)

$dir = $split[Ubound($split)-2]

ConsoleWrite($dir & @CRLF)
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
Mobius

~

Edited by Mobius

Share this post


Link to post
Share on other sites
UEZ

This works, too!

#Include <String.au3>
$string = "\\172.28.206.7\Bservices\LST\AB\file.txt"
$array = _StringExplode($string, "\")
If IsArray($array) Then MsgBox(0, "Test", $array[UBound($array) - 2])

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
AlmarM

Local $String = "\\172.28.206.7\Bservices\LST\AB\file.txt"
Local $Split = StringSplit($String, "\")

MsgBox(0, "", $Split[$Split[0] - 1])

This works.. :]


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.