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 🙂


 

1
Online

353
Users

1.1k
Topics

7.5k
Posts