51 users online (0 members and 51 guests)  


  Results 1 to 6 of 6

Related

  1. reading data line by line from textarea    Forum: ASP Forum
    Replies: 3
  2. How to remove unneeded portions from string?    Forum: CGI Perl Forum
    Replies: 1
  3. Replies: 8
  4. php - sub character    Forum: PHP Forum
    Replies: 1
  1. #1
    hermoine's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Mar 2007
    Posts
    32

    Lightbulb Remove the new line character from the String

    I have a textarea. I need to modify the newline character in the text to comma. I tried split and concating. But that does not seem to work. Can any one help me out?

  2. #2
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732

    Re: Remove the new line character from the String

    Hi there hermoine,

    I am not promising a solution to your problem but it would be helpful to see the code with which you are working.

  3. #3
    hermoine's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Mar 2007
    Posts
    32

    Lightbulb Re: Remove the new line character from the String

    I first tried

    Code:
    var newstr="";
    var strText=document.getElementById('str').value;
    var strArray=strText.split('\n');
    for(int i=0;i<strArray.length;i++){
       newstr=newstr+strArray[i];
    }
    If i am able to remove that new line character then its enough.. rest i will be able to do....

  4. #4
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732

    Re: Remove the new line character from the String

    Hi there hermoine,

    whilst waiting for your reply I came up with this example, which may help...
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <script type="text/javascript">
    window.onload=function(){
    
    df=document.forms[0];
    df[1].onclick=function(){
    
    /***** Firefox only needs this line *****/
    
    df[0].value=df[0].value.replace(/\n/g,',');
    
    /***** IE and Opera need this line also *****/
                         
    df[0].value=df[0].value.replace(/\s/g,' ').replace(/  ,/g,',');  
      }
     }
    </script>
    
    </head>
    <body>
    
    <form action="#">
    <div>
    <textarea rows="10" cols="50">
    </textarea>
    <input type="button" value="remove line breaks">
    </div>
    </form>
    
    </body>
    </html>

  5. #5
    hermoine's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Mar 2007
    Posts
    32

    Lightbulb Re: Remove the new line character from the String

    Thanks a lot... Its working.....

  6. #6
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732

    Re: Remove the new line character from the String

    No problem, you're welcome.



Tags for this Thread