Jump to content

stringtrim


Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

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.

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...