Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: TEXT TO STRING

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default TEXT TO STRING

    I need to generate a string that reads like this...

    Input text:
    PETER
    STEVE
    JOHN

    Output text:
    PETER (1),
    PETER (2),
    STEVE (1),
    STEVE (2),

    I have previously generated a code that would string the input text together for another result but now need the output to look like above result.

    that code was:

    <script language="javascript">

    function fix(starter)
    {
    var toReturn = "";

    var data = document.getElementById("data").innerHTML;
    var lines = data.split("\r\n");
    toReturn = lines.join("', '");
    toReturn = starter + "('" + toReturn + "')"
    document.getElementById('answer').innerHTML = toReturn;

    window.clipboardData.setData("text", toReturn);
    alert('Copied to clipboard!');


    }

    </script>

    <h2>COPY TO CLIP</h2>
    <table>
    <tr>
    <td><b>ENTER:</b></td>
    <td><textarea id="data" rows="10" cols="20"></textarea></td>
    </tr>
    <tr>
    <td><b>SELECT:</b></td>
    <td>
    <input type="button" value="RESULT" onClick="fix('RESULT')">
    </td>
    </tr>
    <tr>
    <td><textarea id="answer" rows="10" cols="20"></textarea></td>
    </tr>
    </table>


    }

    Is there an easy way to do this change with out changing too much??

    Please help as its doing my head in!


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: TEXT TO STRING

    This is a Java forum, find a javascript forum.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: TEXT TO STRING

    Welcome to the forum! Please read this topic to learn how to post code correctly and other useful info for new members.

Similar Threads

  1. extract specific text from a string
    By smemamian in forum Android Development
    Replies: 2
    Last Post: January 18th, 2014, 05:42 AM
  2. Replies: 11
    Last Post: November 12th, 2012, 01:09 PM
  3. Replies: 5
    Last Post: April 7th, 2011, 11:22 AM
  4. reading string in from text file
    By basketball8533 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: December 3rd, 2010, 05:31 PM