Changing a sentence to CamelCase

I recently had to change some text to CamelCase, I searched the forums and while there are discussion on it, I couldn’t come to a solution. I found a Python method, one using an old package called Zebra, the later gave some issues with obsolete packages.

Anyhow, long story short, the below is what I ended up with and I thought it might be of some use to others searching how to do this. I have no doubt it can be improved on, there probably is a package or node I didn’t find but it seems to work.

…and as I just exported the above image, I spot on issue where I’m converting everything to lowercase, incl a CamelCase word.

1 Like

Hello
a solution with Python (using the same logic)

var = "text to convert to CamelCase"
OUT  = ''.join(x[0].upper() + x[1:] for x in var.split(' '))

I found some python code to do it but it never worked for me

“OUT = map(str.title, IN[0])”;

How do I get your code to work so it converts an input from a string?


//
OUT = ''.join(x[0].upper() + x[1:] for x in IN[0].split(' '))

1 Like

@JoziB Nodes from Rhythm & Designtech package can help as well!
Capture

2 Likes

I’m not able to get that to work. I had a problem earlier with Data-Shapes and (I think) the input being a list rather than a string, this looks to be the same.

@AmolShah
I have Rythem but I must be on an older version which doesn’t have that node. And un-aware of the designtech package! I’ll download/update my packages!

try this if you want a string at the output

import clr
import sys

toSingle = lambda x : x[0] if isinstance(x, list) else x
input = toSingle(IN[0])
OUT = ''.join(x[0].upper() + x[1:] for x in input.split(' '))

or if you want a list at the output

import clr
import sys

toList = lambda x : x if isinstance(x, list) else [x]
inputLst = toList(IN[0])
out = []
for lst in inputLst:
	out.append(''.join(x[0].upper() + x[1:] for x in lst.split(' ')))

OUT = out
1 Like

Thanks, both of those worked for me in the script! I was able to cut out everything in my first post :joy: