【问题标题】:Eggplant/Sensetalk parsing and separating a string with capitalized wordsEggplant/Sensetalk 用大写单词解析和分隔字符串
【发布时间】:2012-01-09 23:05:19
【问题描述】:

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

Put "MyTextIsHere" into exampleString

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

"My Text Is Here"

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

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

【问题讨论】:

    标签: string parsing gui-testing eggplant


    【解决方案1】:

    请参阅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
    

    【讨论】:

      猜你喜欢
      • 2015-10-27
      • 1970-01-01
      • 1970-01-01
      • 2014-06-24
      • 2018-09-07
      • 2012-05-13
      • 2019-11-22
      • 2016-12-04
      • 1970-01-01
      相关资源
      最近更新 更多