Question

I'm in need of the ability to parse and separate a text string using Sensetalk (the scripting language the Eggplant GUI tester uses). What I'd like to be able to do is provide the code a text string:

Put "MyTextIsHere" into exampleString

And then have spaces inserted before every capital letter save for the first, so the following is then stored in exampleString:

"My Text Is Here"

I basically want to separate the string into the words it contains. After searching the documentation and the web, I'm no closer to finding a solution to this (I agree, it would be far easier in a different language - alas, not my choice).

Thank you in advance to anyone who can provide some insight!

Was it helpful?

Solution

See question at http://www.testplant.com/phpBB2/viewtopic.php?t=2192.

With credit to Pamela at TestPlant forums:

set startingString to "HereAreMyWords"
set myRange to 2 to the number of characters in startingString //  The range to iterate over– every character except the first

Put the first character in startingString into endString // The first character isn't included in the repeat loop, so you have to put it in separately

repeat with each character myletter of characters myRange of startingString
   if charToNum(myLetter) is between 65 and 90 // if the character's unicode number is between 65-90...
      Put space after endString
   end if
   Put myLetter after endString
end repeat

put endString

or you could do it this way:

Put "MyTextIsHere" into exampleString
repeat with each char of chars 2 to last of exampleString by reference
    if it is an uppercase then put space before it
end repeat
put exampleString
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top