Jump to content

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

Thanx

Link to comment
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
            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
Link to comment
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:

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