我需要能够使用Sensetalk(Eggplant GUI测试人员使用的脚本语言)解析和分离文本字符串。我希望能够做的是为代码提供一个文本字符串:
Put "MyTextIsHere" into exampleString
然后在每个大写字母保存第一个之前插入空格,然后将以下内容存储在 exampleString 中:
"My Text Is Here"
我基本上想把字符串分成它包含的单词。在搜索了文档和网络之后,我没有找到解决方案(我同意,用不同的语言会更容易 - 唉,不是我的选择)。
提前感谢能够提供一些见解的任何人!
答案 0 :(得分:2)
在http://www.testplant.com/phpBB2/viewtopic.php?t=2192查看问题。
在TestPlant论坛上获得Pamela的信任:
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
或者你可以这样做:
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