How do I trim a textfield string that contains numbers & characters to only use the numbers for a calculation? - InfoPath Dev
in

InfoPath Dev

How do I trim a textfield string that contains numbers & characters to only use the numbers for a calculation?

Last post 03-22-2013 05:19 AM by supermanKelz. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 03-21-2013 09:48 AM

    How do I trim a textfield string that contains numbers & characters to only use the numbers for a calculation?

    Hey all!  This seemed like a newbie question so here it goes!

     I am trying to take user input from a dropdown menu that has custom list items that have a TEXT display name and TEXT+NUMERIC value.  For example, if a user selects "one time" from the dropdown, then Execution field holds the value "one-time50".  I'm doing this because the selections need to hold a text value and a numeric value for calculation and summary display purposes.

     Now, what I want to do with the execution field that has the value of "one-time50" is to have a text field display "one-time" and another field holds "50" that can be added to a formula for a calculation.

     Any suggestions???

     Thanks!

    Filed under: , ,
  • 03-21-2013 03:34 PM In reply to

    Re: How do I trim a textfield string that contains numbers & characters to only use the numbers for a calculation?

    Hi supermanKelz,

    You can extract the text only by removing the numbers with the translate function:

     translate(myUserInput,"0123456789", "")

    And you can extract the numbers only by removing the letters and the dash with another call to the translate function:

    translate(myUserInput, "ABCDEFGHIJKLMNOPQRSTUVWYXZabcdefghijklmnopqrstuvwyxz-","")

    Jennifer Lindsay
    Qdabra® Software/InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™

  • 03-21-2013 05:08 PM In reply to

    Re: How do I trim a textfield string that contains numbers & characters to only use the numbers for a calculation?

    Thanks so much, about to try it out now!
  • 03-22-2013 05:19 AM In reply to

    Re: How do I trim a textfield string that contains numbers & characters to only use the numbers for a calculation?

    Ok part 2 time. 

     I've gotten the translate function to replace the parts of the string that I want, works great thanks!  However, I'm having trouble figuring out the formula to perform the translate on a multiple selection list box.

     Currently, I'm using this formula to keep track of ALL selected options in the list box: eval(eval(field1, 'concat(., ";")'), "..")  This formula produces: Option-1; Option-2; Option-3.  Now what I want to do is change the formula a bit so that it incorporates the TRANSLATE function to remove the text ("Option-" in this case), and sum the remaining numerical values (1, 2, 3) so that "6" is stored in a field (the field that holds the formula as default value).

     Thanks for your help again!

    JenniferLindsay:

    Hi supermanKelz,

    You can extract the text only by removing the numbers with the translate function:

     translate(myUserInput,"0123456789", "")

    And you can extract the numbers only by removing the letters and the dash with another call to the translate function:

    translate(myUserInput, "ABCDEFGHIJKLMNOPQRSTUVWYXZabcdefghijklmnopqrstuvwyxz-","")

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