How to remove a whitespace between words in a $Name

Hi, I have been struggling to rename a group of files by trying to eliminate the whitespace between 2 words in a $Name. In other words, I would like to rename a document by eliminating the white space between the words.

For example:$Name== “Word1 Word2 Word3” wanting to rename to $Name==“Word1Word2”
How do I remove whitespaces between words in a $Name?

Thanks in advance
Tom

$MyString = $Name.replace("^(\w+) (\w+).*",$1$2);

As in:
name-fix1

Doesn’t need to be a rule - could be an agent action, but I think this addresses your scenario (at least, as defined above)

Excellent, thanks Mark, this works perfectly in my example above. Thank you. I am just beginning to use the “replace” operator. This helps.

I have a follow up slightly more expanded question. I am trying to convert some title names in an older tinderbox file from word1 word2 word3 word3 to CamelCase format. In my example, how do I remove the whitespaces in all the words AND capitalize each word?

Example
“this is my old file name” to “ThisIsMyOldFileName”

Thanks again for all your help as always.
Tom

Try this:

name-fix2

So, we split the original $Name into words, based on the premise of a single space between words.

Then we set $MyString (or in your case $Name) to be the capitalised versions of word 1 and word two concatenated to a single string. Then we reset $MyList to default so we don’t save any cruft.

See also:

Thank you Mark. Very helpful. Thanks for your continued work.

Tom

1 Like