【问题标题】:How can i remove a string at the end of a main string and display it?如何删除主字符串末尾的字符串并显示它?
【发布时间】:2014-04-22 16:37:36
【问题描述】:

我正在研究 TC9 并使用 jscript。我必须从文本中删除一个字符串并进行比较。 例如:文本 12:11:12

在上面的文字中,我需要提取显示时间的部分。我该怎么做?

谢谢

【问题讨论】:

  • 感谢您的回复。还有无论如何要找到一个字符串是否有一个子字符串和一个正则表达式?在上面的字符串“Text 12:11:12”中,我如何验证字符串是否包含子字符串“Text”和正则表达式?

标签: jscript testcomplete


【解决方案1】:

如果源字符串一直是这种格式,你可以直接获取空格后面的部分:

function test()
{
  var str = "Text 12:11:12";
  var timeStr = str.split(" ")[1];
  Log.Message(timeStr);
}

【讨论】:

    【解决方案2】:

    以下代码应该可以工作:

    function Test()
    {
      var regEx, Matches;
      var InStr = "Text 12:11:12";
    
      // Set regular expression pattern 
      regEx = /\d*:\d*:\d*/ig;
    
      // Perform search operation
      Matches = InStr.match(regEx);
      // Iterate through Matches array
      for (var i=0; i<Matches.length; i++)
        {
        Log.Message(Matches[i]);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2010-11-05
      • 2019-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多