• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Correct way to search for character within a string

Explorer ,
Sep 15, 2014 Sep 15, 2014

Copy link to clipboard

Copied

I am trying to search for the occurrence of a "(" within a text string - unfortunately my code is reported as incorrect.

I extract the text correctly but cannot create the search statement correctly:

var mylistpgftext = pgf.GetText (Constants.FTI_String)   

for (var i=0; i < mylistpgftext.length; i++)             

{                                                        

    var mylistitem = mylistpgftext.sdata              

    var mybracketpos = mylistitem.search(/(/i)    --------------error line-----------------       

    if (mybracketpos != -1)                              

    {                                                    

      alert(mylistitem)                                  

    }                                                    

}                                                       

TOPICS
Scripting

Views

334

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 15, 2014 Sep 15, 2014

Hi Bob, I did not test this, but I think the problem is an unescaped character in your regular expression. Try this.

var mybracketpos = mylistitem.search(/\(/i);

Notice the backslash before the open parens that you are searching for.

-Rick

Votes

Translate

Translate
Community Expert ,
Sep 15, 2014 Sep 15, 2014

Copy link to clipboard

Copied

Hi Bob, I did not test this, but I think the problem is an unescaped character in your regular expression. Try this.

var mybracketpos = mylistitem.search(/\(/i);

Notice the backslash before the open parens that you are searching for.

-Rick

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Sep 16, 2014 Sep 16, 2014

Copy link to clipboard

Copied

If a regular expression isn't required, I would think that indexOf would be easier:

var mybracketpos = mylistitem.indexOf("(");

Russ

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 16, 2014 Sep 16, 2014

Copy link to clipboard

Copied

LATEST

Hi Russ and Rick,

Finger trouble with Rick reply.

They both work perfectly!!

Many thanks to you both.

Bob

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines