Is there a more handy way to convert a text with special characters to be safe to be used as a filename?
I have done the code like that, but i think there is probably a more clean solution.
"--- Variablen ---";
let KundeConverted := Kunde.'Firma oder Nachname';
let KundeConverted := replace(KundeConverted, "*", "_");
let KundeConverted := replace(KundeConverted, "|", "_");
let KundeConverted := replace(KundeConverted, "/", "_");
let KundeConverted := replace(KundeConverted, "ö", "oe");
let KundeConverted := replace(KundeConverted, "ä", "ae");
let KundeConverted := replace(KundeConverted, "ü", "ue");
let KundeConverted := replace(KundeConverted, "ß", "ss");
let KundeConverted := replace(KundeConverted, "&", "und");
Any idea?
Greets, Michael
4 replies
-
I just tagged 2 regex specialists because i think this can be done with regex....
-
As far as I know, a regexp engine does not include a general "translate with table" (TRT for veteran IBM programmers), so one must use some kind of iteration. One can iterate on the potential replacements, like you did, or iterate on the elements of the input string. The latter can be preferable if the input string is short, and the potential translations numerous.
let it := "*|/öäüß&"; let ot := ["_", "_", "_", "oe", "ae", "ue", "ss", "und"]; join(for c in Text do let i := index(it, c); if i < 0 then c else item(ot, i) end end, "")
-
Another option would be to wrap what you have in a function or global function especially if you use the code in more than one place.
Also, I don’t think you need to use let after
let KundeConverted := Kunde.'Firma oder Nachname';
Just use KundeConverted := for each of the following lines.
Content aside
- 1 mth agoLast active
- 4Replies
- 35Views
-
4
Following