Search and Replace Text Within a String

(imported topic written by SystemAdmin)

What I am trying to do is replace the “-” in this string with “-2d”. So I have a string “my-site-location” I want it to look like “my-2dsite-2dlocation”. I’ve looked through the relevance guide and this forum and was not able to find an easy way to do this.

The reason I need this is because we are writing a script to subscribe computers with a property value to a custom site, but with the custom sites, you need to change these special character’s around.

(imported comment written by SystemAdmin)

The other piece of this is I don’t know how many “-” may be in the string.

(imported comment written by NoahSalzman)

Try:

concatenation “-2d” of (substrings separated by “-” of “my-site-location”)

(imported comment written by SystemAdmin)

perfect, thank you so much

(imported comment written by SystemAdmin)

This is good stuff.

Is there a way I can replace a specific character number? I am trying to figure out the best way of replacing the 17th character of a string. Thanks!

(imported comment written by NoahSalzman)

If you know the full length of the string you can do something like this to swap x with z:

concatenation of ((first 16 of it; “z”; last 3 of it) of “1234567890123456x890”)

Also, for your amusement, here is a really ugly way to do the same thing with regex:

concatenation of ((parenthesized parts (1) of matches (regex “^(…)(.)(.)") of it; “z”; parenthesized parts (3) of matches (regex "^(…)(.)(.)”) of it) of “1234567890123456x890”)

(imported comment written by BenKus)

Here is a slight modification to Noah’s relevance so you don’t need to know the length of the string:

concatenation of ((first 16 of it; “z”; last (length of it - 17) of it) of “1234567890123456x890”)

Ben

(imported comment written by len123)

Hello,

Im trying to convert the following string from “Version 15 Release 5 Level 0.0” to “15.5.0.0” so that I can evaluate it as a version and compare it if it is >= “15.5.1.100”

I tried the following

Q:(concatenation “” of (matches (regex "

http://0-9.

") of ((“Version 15 Release 5 Level 0.0”) as string)))

A: 1550.0

thanks!

(imported comment written by len123)

sorry for the typo…

Syntax is …

concatenation “” of matches (regex "

0-9

") of (“Version 15 Release 5 Level 0.0”) as string

(imported comment written by Lee Wei)

One possibility:

q: concatenation “.” of (it as string) of (it as floating point | “999” as floating point) whose (it != “999” as floating point) of substrings separated by " " of “Version 15 Release 5 Level 0.0”

A: 15.5.0.0

The idea is:

  • Take everything apart separated by space or spaces
  • Identify the digit by casting to float points. If it fails, it is not a digit
  • Stitch them back with “.”

Lee Wei

(imported comment written by len123)

Thank you Lee!!