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
Solved! Go to Solution.
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 " "
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})))
Thank you very much for that James, that has worked perfectly! Really appreciate your help (and quick response), helped me out big time.
Hi there, Is Find and replace available yet?
Hi Kassandra,
No, this is not possible in Survey123 in a calculate question, the best workaround is as James describes above.
Phil.
Hello,
does the Find and replace function exist now?
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 " "
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,
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!
No worries Katherine - you're quite welcome. I'm glad it helped