String Functions
-
Could we have a some string manipulation functions, I'm thinking of ways to capitalize words for UI labels, control text and other on screen stuff. This will be really useful with the fact we can use custom fonts because then pretty much all UI text can be done within HISE instead of having to load in images.
I have a particular case where I'm using each container's ID as an articulation name and I want to output this name on the UI but I need to format it so that the spacing and capitalization is nicer than what I've used for naming the containers which is more script friendly than user friendly.
-
Yeah, there are a ton of String manipulation methods in JUCE that I can add a wrapper for. Just give me a list of everything that seems to be useful to you.
-
Wonderful :)
- lastIndexOf()
- slice()
- toUpperCase()
- toLowerCase()
- subStr();
- replace();
- charAt();
I couldn't find a function in the JUCE reference to capitalise each word but I believe it is achievable with a combination of some of the above functions and a little regex. http://stackoverflow.com/questions/196972/convert-string-to-title-case-with-javascript/196991#196991
-
Slice -> toUppercase -> join ?
-
Alright, I added these method (along with the autocomplete popup for String and Array functions).
You can capitalize a string like this:
var string = "this is not uppercased"; inline function capitalize(stringToCapitalize) { local firstLetter; local wordList = stringToCapitalize.split(" "); local uppercaseList = []; for(word in wordList) { firstLetter = word.substring(0, 1); firstLetter = firstLetter.toUpperCase(); word = firstLetter + word.substring(1, 999); uppercaseList.push(word); } return uppercaseList.join(" "); }; var result = capitalize(string); Console.print(result);
-
Thanks Christoph, I don't know where you find the time to do all this but I'm glad you do :)
-
I am currently traveling by train and this is the perfect kind of light coding work that shortens the travel time :)
-
This post is deleted! -
@Christoph-Hart said in String Functions:
You can capitalize a string like this:
I'm using this quite often so decided to add it to the source code as
String.toStartCase()
. https://github.com/christophhart/HISE/pull/284Maybe the function should be called capitalise or capitalize, what do you guys think?
Edit: This currently causes a build error on MacOS. So don't use it yet :)
Edit2: I fixed the bug on Mac and changed the function name to .capitalize because I think it makes it more understandable.