Convert from C# function to JavaScript function
<p>I have a function in c# that used to manipulate the string, It works well while I used in C#. Now I want to convert this function to use in JavaScript. This is the function in C#:</p>

<pre><code> public static string TrimString(string str, int lenght)
 {
        string _str = str;

        int _iAdditionalLenght = 0;

        for (int i = lenght; i &lt; str.Length; i++)
        {
            if (_str.Substring(i, 1) == " ")
                break;

            _iAdditionalLenght++;
        }

        return str.Substring(0, str.Length &lt; (lenght + _iAdditionalLenght) ? str.Length : (lenght + _iAdditionalLenght));

 }
</code></pre>

<p>I converted it to javascript :</p>

<pre><code>function TrimString(str, lengthStr) { //this is my testing 4
     var _str = str;
     var _iAdditionalLenght = 0;
     for (var i = lengthStr; i &lt; str.length; i++) {
       if (_str.substring(i, 1) == " ")
           break;
       _iAdditionalLenght++;
     }

     return str.substring(0, str.length &lt; (lengthStr + _iAdditionalLenght) ? str.length : (lengthStr + _iAdditionalLenght));
 }
</code></pre>

<p>But the javascript doesn't work.</p>

<p>Could anyone tell me, how could I do it in JavaScript function?</p>
