Find and Replace Character

4875
10
Jump to solution
10-25-2017 09:26 PM
DanielMcIlroy
Occasional Contributor

Hi All,

 

Interesting question, I need to generate a filename by concatenating a series of values from the survey form.

 

One of these values has been changed from an integer to a decimal field, meaning that decimal points are now an issue. The user would like to replace the "." with a "p", however I am unsure how to make this happen as a calculate in S123. Is it even possible?

 

Help would be greatly appreciated.

 

Cheers

Dan

1 Solution

Accepted Solutions
ShaunKolomeitz1
New Contributor II

I know this is an old topic, but my simple workaround recently was to use the Javascript custom scripts and add a simple helper function :

/* My script is called functions.js which contains the following

function findandreplace(inStr, findstr, replacestr) {
     return inStr.split(findstr).join(replacestr);
}

The script is called using a Calculate in Survey123: 

pulldata("@javascript", "functions.js", "findandreplace", ${treatment_outcome},"_"," ")

/* here I wanted to replace underscores "_" with a space " "

View solution in original post

10 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Dan,

There isn't a function to find/replace text that are in arbitrary positions.  In your case, there is a special way to work around since we can get the length of the integer portion via type conversion and then use the substr() function to extract to the left and right of the decimal; for a decimal question called d1:

concat(substr(string(${d1}), 0, string-length(int(${d1}))), "p", substr(string(${d1}), string-length(int(${d1}))+1, string-length(${d1})))

DanielMcIlroy
Occasional Contributor

Thank you very much for that James, that has worked perfectly! Really appreciate your help (and quick response), helped me out big time.

0 Kudos
KassandraRodriguez
Occasional Contributor

Hi there, Is Find and replace available yet?

0 Kudos
by Anonymous User
Not applicable

Hi Kassandra,

No, this is not possible in Survey123 in a calculate question, the best workaround is as James describes above.

Phil.

0 Kudos
DelaereMickael
Occasional Contributor II

Hello,

does the Find and replace function exist now?

ShaunKolomeitz1
New Contributor II

I know this is an old topic, but my simple workaround recently was to use the Javascript custom scripts and add a simple helper function :

/* My script is called functions.js which contains the following

function findandreplace(inStr, findstr, replacestr) {
     return inStr.split(findstr).join(replacestr);
}

The script is called using a Calculate in Survey123: 

pulldata("@javascript", "functions.js", "findandreplace", ${treatment_outcome},"_"," ")

/* here I wanted to replace underscores "_" with a space " "

DanielRivero
New Contributor II

I don´t know why there is not a replace function on survey, the fact is that javascript is not a good idea when working offline using ipad, there is a random logoff issue, and javascript is not working when not logged in. 

Any idea if there is a better way to solve a replace string.

 

Regards,

0 Kudos
Katie_Clark
MVP Regular Contributor

Just wanted to say thanks for coming back to the question and posting your response even though the original question is from 2017 - it helped me immensely! 

Best,
Katie


“The goal is not simply to ‘work hard, play hard.’ The goal is to make our work and our play indistinguishable.”
- Simon Sinek
ShaunKolomeitz1
New Contributor II

No worries Katherine - you're quite welcome. I'm glad it helped

0 Kudos