web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Indexof doesn't find t...
Power Automate
Unanswered

Indexof doesn't find the string when the search text contains two spaces

(0) ShareShare
ReportReport
Posted on by 292

I am parsing a generated email to pluck out specific Change Request #'s

       When a new email comes in (with a subject line match)

       Convert the body of the email to simple text using HTML To Text action

       Use IndexOf() to locate anchor text to pluck out the value.

 

       For example, to pluck out the Change Request # for Linux from the email body text:

                       Linux Change Request:  CHG0099999       <<<< note there are two spaces after the colon

 

       I wrote a Compose statement to get the position of the anchor text:

                       indexOf(body('Html_to_text'),'Linux Change Request:  ')    <<<two spaces after colon 

       It returns a -1 when the search text ends in a double space.

 

       If I get rid of the 2nd space it works (gets a match and returns the string's position)   

 

Is this a bug in the software?  Something about double-spaces in IndexOf() search parameter that it doesn't like?  

 

 

 

 

 

Categories:
I have the same question (0)
  • VJR Profile Picture
    7,635 on at

    Hi @MelissaReed 

     

    When I give the input same as the one in your post

    Input:

    Linux Change Request:  CHG0099999

     

    The output of indexOf shows as 0 (which is correct because the desired string starts from 0th position)

    I'm using the same Expression from your post.

     

    indexOf(triggerBody()['text'],'Linux Change Request:  ')
     

    VJR_0-1634958315766.png

     

     

    As an example I gave another input as below

    Input:

    check now Linux Change Request: CHG0099999

     

    and it returned output as 10 (which is correct because now it starts from 10th position)

     

    VJR_1-1634958450046.png

     

    The only thing I am not doing in my sample process is the Html to text, but it shouldn't matter because double spaces are working fine in the indexOf expression.

     

    Just make sure if there is some kind of invisible character like a newline or a carriage return or if something else in the input string is coming after doing the html to text.

     

    This can be done by "seeing" the invisible characters in an Editor like Notepad++ [free] (or maybe UltraEdit?)

     

    Below is an example using Notepad++   (View menu->Show symbol->Show all characters)

     

    The single dot within blue box is a single space

    The two dots within the red box are double spaces

    And CR implies carriage return whereas LF implies line feed.

    VJR_2-1634958776793.png

     

     

    The same text above cannot be viewed with a normal text editor below

     

    VJR_3-1634958876600.png

     

    That way you can see if something is not matching and causing the indexOf to show -1 instead of the right position.

     

     

     

     

  • MelissaReed Profile Picture
    292 on at

    Thanks for the reply.   I actually put the text through an ASCII converter to see if what looked like a space was something other than an ASCII 32.  It came through as 32 and 32.

    When I take out the space it works.  When I make it two spaces, it fails.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard