سؤال

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