Jump to content
Sign in to follow this  
Andre Celie

Split variable how to?

Recommended Posts

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


Share this post

Link to post
Share on other sites

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
        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) 
                    $sTmp &= StringMid($GCR, $i, 1)
            GUICtrlSetData($Input, $sTmp)


Edited by smashly

Share this post

Link to post
Share on other sites

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:

 $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:


Edited by weaponx

Share this post

Link to post
Share on other sites

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


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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...