Jump to content
Sign in to follow this  
rootx

How can I find the max value whith StringSplit

Recommended Posts

Hello friends,

I need to extrapolate the max value from this cicle.

Object: remove everything before the last backslash to have "img" folder without the path

 

Example()

Func Example()
    Local $sText = "C:folder1folder2img"
    Local $aArray = StringSplit($sText, '', $STR_ENTIRESPLIT)
    For $i = 1 To $aArray[0]

              MsgBox($MB_SYSTEMMODAL, "", "$aArray[" & $i & "] - " & $aArray[$i])

   Next

EndFunc

Tanks

Edited by rootx

Share this post


Link to post
Share on other sites

Do you mean the total indexes in the array? You would just look at the value of $aArray[0].

Example()

 Func Example()
     Local $sText = "C:\folder1\folder2\img"
     Local $aArray = StringSplit($sText, '\', 1)
        MsgBox(0, "", $aArray[0])
 EndFunc
Edited by JLogan3o13

Share this post


Link to post
Share on other sites

Local $sText = "C:\folder1\folder2\img"
Local $sText1 = "C:\folder1\img"
Local $aArray = StringSplit($sText, '\')
Local $aArray1 = StringSplit($sText1, '\')
Local $var = $aArray[0], $var1 = $aArray1[0]
ConsoleWrite($aArray[$var] & @LF & $aArray1[$var1] & @LF)

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Here some variants which came to my mind:

#include <File.au3>
Local $sText = "C:\folder1\folder2\img"

;variant 1
ConsoleWrite("1: " & StringRight($sText, StringLen($sText) - StringInStr($sText, "\", 0, -1)) & @CRLF)

;variant 2
ConsoleWrite("2: " & StringTrimLeft($sText, StringInStr($sText, "\", 0, -1)) & @CRLF)

;variant 3
ConsoleWrite("3: " & StringMid($sText, StringInStr($sText, "\", 0, -1) + 1) & @CRLF)

;variant 4
ConsoleWrite("4: " & StringRegExpReplace($sText, "^.*\\(.*)$", "$1") & @CRLF)

;variant 5
Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
Local $aPathSplit = _PathSplit($sText, $sDrive, $sDir, $sFilename, $sExtension)
ConsoleWrite("5: " & $aPathSplit[3] & @CRLF)

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

Thanks everyone,

UEZ... wonderfully great answer.

My solution

;set path

Local $imgfolder = FileSelectFolder("Inserisci il nome della cartella che contiene le immagini", "", "", @ScriptDir)

;write value to init.txt

FileWrite($file,(StringRight($imgfolder, StringLen($imgfolder) - StringInStr($imgfolder, "", 0, -1))))

works fine.

Edited by rootx

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  

×
×
  • Create New...