Question

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

Was it helpful?

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

OTHER TIPS

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top