HISE Logo Forum
    • Categories
    • Register
    • Login

    String Functions

    Scheduled Pinned Locked Moved Feature Requests
    9 Posts 3 Posters 1.5k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • d.healeyD
      d.healey
      last edited by

      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.

      Libre Wave - Freedom respecting instruments and effects
      My Patreon - HISE tutorials
      YouTube Channel - Public HISE tutorials

      1 Reply Last reply Reply Quote 0
      • Christoph HartC
        Christoph Hart
        last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • d.healeyD
          d.healey
          last edited by d.healey

          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

          Libre Wave - Freedom respecting instruments and effects
          My Patreon - HISE tutorials
          YouTube Channel - Public HISE tutorials

          1 Reply Last reply Reply Quote 0
          • Christoph HartC
            Christoph Hart
            last edited by

            Slice -> toUppercase -> join ?

            1 Reply Last reply Reply Quote 0
            • Christoph HartC
              Christoph Hart
              last edited by

              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);
              
              d.healeyD 1 Reply Last reply Reply Quote 2
              • d.healeyD
                d.healey
                last edited by

                Thanks Christoph, I don't know where you find the time to do all this but I'm glad you do :)

                Libre Wave - Freedom respecting instruments and effects
                My Patreon - HISE tutorials
                YouTube Channel - Public HISE tutorials

                1 Reply Last reply Reply Quote 0
                • Christoph HartC
                  Christoph Hart
                  last edited by

                  I am currently traveling by train and this is the perfect kind of light coding work that shortens the travel time :)

                  1 Reply Last reply Reply Quote 2
                  • LindonL
                    Lindon
                    last edited by

                    This post is deleted!
                    1 Reply Last reply Reply Quote 0
                    • d.healeyD
                      d.healey @Christoph Hart
                      last edited by d.healey

                      @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/284

                      Maybe 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.

                      Libre Wave - Freedom respecting instruments and effects
                      My Patreon - HISE tutorials
                      YouTube Channel - Public HISE tutorials

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post

                      13

                      Online

                      1.7k

                      Users

                      11.8k

                      Topics

                      102.8k

                      Posts