Need help with Regex, string.length

    Apr 02 2012 | 1:40 am
    I'm at my wit's end, so any help would be greatly appreciated! I want to find trailing whitespace at the end of a string, then adjust the string's length accordlingly. This is what I have so far:
    space = /''$/g; kitstring = kitstring.replace(/''$/g, null);
    for (i = 9; i > 0; i--) { if (kitstring[i] == space) { kitstring.length = kitstring.length--; } }
    I've tried many things, and looked around in the forum. Am I doing something wrong with regex or kitstring.length? No matter what I do the string length always appears as "10" in the max window.

    • Apr 02 2012 | 2:19 am
      I don't know if max's implementation of strings in JavaScript has the trim operator. But lots of different answers to your question here
    • Apr 02 2012 | 6:53 am
      Yep, seen that. It's just real tricky, because i post the string to the Max window as well. I test "X ", but it appears as "X", which is well and good, but the length of the string is still 10. I'm pretty sure this prevents the strings concatenating properly.
      If the string is say "Rebellion2", then it concats properly with ".syx", then the file writes correctly in windows.
      Thanks though, dhjdhjdhj, I'll take a closer look at that link.
    • Apr 05 2012 | 12:34 pm
      for (i = 10; i < 20 && kit[i] != ""; i++, k++)
      		kitchar[k] = String.fromCharCode(kit[i]);
      In the spirit of "the OP should post the solution when/if found", the problem area of my code was in another function which i considered to be out of the scope of the problem. Of course, looking back now, I probably should've posted more code and the fact that I was trying to translate a sysex string. Lesson learned.
      ... && kit[i] != "";
      In other words, keep copying the array over until a Null character is reacher. This is hard to determine at first glance, unless you know the difference between the ascii codes for Space and Null. Looking at the Max window I had no idea what the hell was going on.
      Anyway, I'm talking to myself. Good day.