문제

I am working on TC9 and using jscript. I have to remove a string from a text and perform a comparison. For example : Text 12:11:12

In the above text , i need to extract the portion showing time.How do i do that?

Thanks

도움이 되었습니까?

해결책 2

The following code should work:

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]);
    }
}

다른 팁

If the source string always has this format, you can just get the part after the space:

function test()
{
  var str = "Text 12:11:12";
  var timeStr = str.split(" ")[1];
  Log.Message(timeStr);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top