0

我需要使用 Sensetalk(茄子 GUI 测试人员使用的脚本语言)解析和分离文本字符串的能力。我想做的是为代码提供一个文本字符串:

Put "MyTextIsHere" into exampleString

然后在每个大写字母之前插入空格以保存第一个,因此将以下内容存储在exampleString中:

"My Text Is Here"

我基本上想将字符串分成它包含的单词。在搜索了文档和网络之后,我并没有找到解决这个问题的方法(我同意,用另一种语言会容易得多 - 唉,不是我的选择)。

提前感谢任何可以提供一些见解的人!

4

1 回答 1

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
于 2012-01-11T13:40:35.623 回答