How do i replace multiple occurrences of a word or stringset in a field? - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

How do i replace multiple occurrences of a word or stringset in a field?

Last post 04-18-2016 07:58 AM by rayzermatic. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 04-14-2016 01:21 PM

    How do i replace multiple occurrences of a word or stringset in a field?

    What I have done is use translate( field,"` ~!@#$%^&*()=+\/][}{;:?><,.'","____________________________________") to change special characters into underscores.

    However, sometimes I end up with several occurrences of double underscores in the field.

    I want to remove the double underscores("__") and replace all of them with a single underscore.

    I have used concat(substring-before(field,"__"),"_",string-after(field,"__")) and it will remove the first occurrence.

    What I need is something like the double eval or something to loop through the whole line and get them all.

    Thanks 

     

     

  • 04-18-2016 06:57 AM In reply to

    Re: How do i replace multiple occurrences of a word or stringset in a field?

    Hello rayzermatic! 

    It turns out that this is somewhat difficult to do with InfoPath's built-in functionality.

    One option is to use a recursive approach: put a rule on the field like this:

      Condition: field contains "__"

      Action: set field to concat(substring-before(field, "__"), "_", substring-after(field, "__"))

    This will repeatedly modify the field until the double underscores are gone, however if this repeats more than the allowed number of rule repetitions (8 in browser forms, 16 in filler forms), the rules will stop executing and the user will see a nasty error.

    Another option is to use qRules' ReplaceString command. This is the simplest approach, but requires you to have qRules:

        ReplaceString /xpath=/path/to/field1 /string1=__ /string2=_

    There is one more option that uses an XML secondary data connection and some tricky rules to carry out the operation. It's a bit time consuming to put together and an example and therefore outside the scope of what we provide for free on this forum, but we can prepare you a sample if you'd be willing to purchase one Qdabra support pack. 

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 04-18-2016 07:58 AM In reply to

    Re: How do i replace multiple occurrences of a word or stringset in a field?

    Thanks Jimmy!

    That helps. I will do the  Condition: field contains "__" but add to it, three conditions to trim it hopefully reducing the total possible iterations to error issue. (All my forms run in browser so I only get eight.)

    What I'll do is create three rules on the field.

    1. The first will run if the field has four underscores and replace them with one 

    2. The next one will look for three underscores and replace them with one.

    3. And the final will look for two underscores and replace them with one.

    Hopefully get them all in a single pass except maybe with #3 having to go one or two more max.

    Thanks for your help. 

    Ray 

Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.