Sign in to follow this  
Followers 0
Andre Celie

Split variable how to?

4 posts in this topic

Is it possible to split a file name which contains the following structure?

ThisIsATest, which needs to be like this: This Is A Test

Same problem I have when there is a number within the filename like this

5ClocksAround : 5 Clocks Around

Thanx

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi, I'm not sure how to do it, but I think StringRegExpReplace() function could do it with the right expression/pattern match.

Here's a crude example using StringReplace() instead..

#include <GUIConstantsEx.au3>

$hGui = GUICreate("Add Spaces", 350, 300)
GUICtrlCreateGroup("Input text to space", 10, 10, 330, 45)
$Input = GUICtrlCreateInput("IAmAStringThatShouldHave7Spaces", 20, 25, 270, 20)
$Button = GUICtrlCreateButton("Go", 300, 25, 30, 20)
GUISetState(@SW_SHOW, $hGui)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            Local $GCR, $sTmp
            $GCR = GUICtrlRead($Input)
            For $i = 1 To StringLen($GCR)
                If StringIsUpper(StringMid($GCR, $i, 1)) Or StringIsInt(StringMid($GCR, $i, 1)) Then 
                    $sTmp &= " " & StringMid($GCR, $i, 1) 
                Else
                    $sTmp &= StringMid($GCR, $i, 1)
                EndIf   
            Next
            GUICtrlSetData($Input, $sTmp)
    EndSwitch    
WEnd

Cheers

Edited by smashly

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I don't understand if you want an array to be retrieved like StringSplit, or if you just want spaces put in the proper places. Anyways...

This will just insert spaces after each word (uncomment the second line to see how it works with numbers):

$string = "ThisIsATest"
;$string = "5ClocksAround"
  $out = StringRegExpReplace($string, '[A-Z0-9][^A-Z]*', '$0 ')
  Consolewrite($out & @CRLF)

This will return an array of all words:

#include<Array.au3>
 $string = "ThisIsATest"
;$string = "5ClocksAround"
  $result = StringRegExp($string, '[[:alnum:]][^[:upper:]]*', 3)
  _ArrayDisplay($result, "Letter pairs, split by upper case letters")

I also wrote this _StringSplitRegExp function which may help you in the future:

http://www.autoitscript.com/forum/index.ph...;hl=stringsplit

Edited by weaponx

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanx just needed 2 codelines for my script and it worked.

Only a smal thing the last Character is a space, don't know kow te solve this

Thanx

Edited by Andre Celie

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