Removing spaces from ASCII text

Home Forums General Programming Removing spaces from ASCII text

Tagged: ,

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #13613
    lfo2vcolfo2vco
    Participant
    • Topics: 26
    • Replies: 162
    • Total: 188
    • ★★

    OK, can’t figure a way of doing this…

    I’m getting text from a uiLabel, this works fine. However the text come from the patch name of a Sysex Dump and there are 15 bytes allocated to the for this task. So if the name is twelve characters long the remaining three characters get filled with spaces thus:

    ASCII = "High Strings   "
    HEX   = "48 69 67 68 20 53 74 72 69 6e 67 73 20 20 20"

    Not a problem till I place this in the name field of a Save File Window then it becomes "High Strings .syx", which looks rubbish.

    So is there a crafty method I can use to remove more that one space in a row?

    Here is some noise I organised into an acceptable format:
    https://soundcloud.com/lfo2vco/a-dark-crystal

    #13620
    msepsismsepsis
    Participant
    • Topics: 219
    • Replies: 732
    • Total: 951
    • ★★★

    I might not be explaining this clearly but here’s vaguely how I would approach it:
    Before placing HEX in the name field of a Save File Window, assign the value of each byte of HEX each to a unique variable. Check each variable starting from the last to see if it’s value is 20. If the last value in the sequence == 20, truncate it, then check the next and continue to check the next last variable’s value. By truncate I mean reconstruct HEX with your variables, but omit the last variable if it’s value equals 20.

    Might be a faster way though but this would get it done.

    • This reply was modified 6 years, 12 months ago by msepsismsepsis.

    Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen

    #13625
    atomatom
    Participant
    • Topics: 157
    • Replies: 2943
    • Total: 3100
    • ★★★★★

    You have the String class at your disposal in Lua, so http://www.juce.com/juce/api/classString.html#ad3853992f01ae00f2e6ed2d4eda85fb6

    #13626
    lfo2vcolfo2vco
    Participant
    • Topics: 26
    • Replies: 162
    • Total: 188
    • ★★

    That’s sweet and should make the process much easier.

    Cheers guys.

    Here is some noise I organised into an acceptable format:
    https://soundcloud.com/lfo2vco/a-dark-crystal

    #13710
    lfo2vcolfo2vco
    Participant
    • Topics: 26
    • Replies: 162
    • Total: 188
    • ★★

    OK, I have been trying to make this work and I found this:

    -- trim whitespace from right end of string
    function trimr(s)
    return s:find'^%s*$' and '' or s:match'^(.*%S)'
    end

    I’m guessing this is related to the String Class Atom made reference to. This is how I got it to work in my method:

    nameData = L(PatchLabel:getProperty("uiLabelText"))
    
    function trim (s)
    return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
    end
    
    nameTrim = (trim(nameData))
    fileToWrite = utils.saveFileWindow("Save patch to disk", File(nameTrim), "*.syx", true)

    Here is some noise I organised into an acceptable format:
    https://soundcloud.com/lfo2vco/a-dark-crystal

    #119681
    zonger
    Participant
    • Topics: 0
    • Replies: 1
    • Total: 1

    Manual space removing may take some time but you can try with some space remover such as https://www.madeintext.com/space-remover/

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
There is currently 0 users and 37 guests online
No users are currently active
Forum Statistics
Threads: 2,417, Posts: 17,039, Members: 57,338
Most users ever online was 12 on January 22, 2019 3:47 pm
Do NOT follow this link or you will be banned from the site!