Fun with String Manipulation's "undocumented features"

For a while now I’ve been using various features of String Manipulation that you won’t generally find documented. I guess therefore, that what I am writing here should be given the caveat “use at your own risk” since it is always possible that in the future, the String Manipulation (and its “(variable)” counterpart node) could be rewritten and the undocumented features would no longer work.

However, since it sits on top of java, and these features make use of its close relationship with java, it is probably fair to assume that this will continue to work in future.

The interesting (to me at least) thing about String Manipulation… at least what I can ascertain from experimenting… is that behind the scenes it uses a java “return” statement, which it then parses to handle all of the String Manipulation syntax. If that return statement contains java-syntax, it is unaffected, and so what I have gathered is that provided what you throw at String Manipulation can syntactically fit into a java return statement, the world is your oyster!

Conditional Expressions.
This is something I do often with String Manipulation as I find it very convenient for simple conditions. see this forum post for details of how nested conditional expressions can be included in String Manipulation:

Random Number generator
A random number can be generated in Java using the standard Random() call. An integer between lower bounday n and upper boundary m inclusive can be produced using:
new Random()).nextInt(m) + n

so a random number between 1 and 6 can be returned by String Manipulation as follows:

toInt(
(new Random()).nextInt(6) +1 
)

Current Date and Time

Java can produce current date and time as a string simply by instantiating a new Date() object, and returning it as a String. So in String Manipulation, current date and time can be returned by:

string(
	new Date()
	)

Universal Unique Identifers (UUIDs)

If you have need of returning a UUID you can use the java UUID package to return a random UUID:

string(

java.util.UUID.randomUUID()
)

Attached is a demo workflow showcasing the above

FunWithStringManipulation.knwf (14.5 KB)

I hope that was of interest. What other simple functions would you find this useful for?

[Edit: I’ve re-uploaded the demo workflow as the nested conditions had a typo]

20 Likes

Mathematical Capabilities

“mathematical capabilities of String Manipulation are often overlooked. Its name is a a misnomer because it can handle (to an extent) numeric calculations too, even being able to return them via the toInt, toLong and toDouble functions.” (Master @takbb )

BR

8 Likes

Great sharing as always @takbb !

3 Likes

Another new (to me!) trick…

Use String Manipulation in conjunction with Cell Splitter to break out a string so each character appears in a new column

string(String.join("\t", $column1$.split("")))

2 Likes

Also, another trick, to return the ascii and unicode codes using String Manipulation

from here

4 Likes

Current date (without time) returned as string in yyyy-M-d format:
string( java.time.LocalDate.now() )

2 Likes

More examples which may be of use should you wish to use a low-code, single node alternative to no-code, multi-node solutions:

yesterday is:

string( java.time.LocalDate.now().minusDays(1))

and tomorrow is:
string( java.time.LocalDate.now().plusDays(1))

also to get name of current month, e.g. SEPTEMBER (which I would assume will appear in the correct format for your locale, but please let me know!):

string( java.time.LocalDate.now().getMonth() )

For the more adventurous :wink: … return today’s date as a string in a specific format using the following construct:

string(
   java.time.format.DateTimeFormatter.ofPattern("MMM dd, yyyy").format(             
         java.time.LocalDate.now()    )
	)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.