Remove the last “\n” from a textarea

后端 未结 5 722
暖寄归人
暖寄归人 2021-02-06 21:30

How to remove the last \"\\n\" from a textarea?

5条回答
  •  离开以前
    2021-02-06 22:03

    from http://en.wikipedia.org/wiki/Trim_%28programming%29

    String.prototype.trim = function() {
      return this.replace(/^\s+|\s+$/g, "");
    };
    

    That will add a trim function to string variables that will remove whitespace from the beginning and end of a string.

    With this you can do stuff like:

    var mystr = "this is my string   "; // including newlines
    mystr = mystr.trim();
    

提交回复
热议问题