DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2005
    Posts
    2

    can anyone convert this code....urgent

    hi everybody.....
    can anybody provide me a java code for the following problem......
    i want that if user enters input like this:

    sam,john,undertaker,rock

    the output should be:

    'sam','john','undertaker','rock'

    i.e , is converted to ',' and the string starts with ' and ends with '

    i have a javascript code for this and it is reproduced below to have full view of the problem.........

    <HTML>


    <BODY>
    <script type="text/javascript">


    function CONVERT(){
    var re=/[,]/g
    for (i=0; i<arguments.length; i++)
    arguments[i].value="'" + arguments[i].value.replace(re, function(m){return replacechar(m)}) + "'"
    }

    function replacechar(match){
    if (match==",")
    return "','"

    }

    </script>

    <form>
    <textarea name="data1" style="width: 400px; height: 100px" ></textarea><br />
    <input type="button" value="submit" name="button" onclick="CONVERT(this.form.data1)">
    </form>

    </BODY>
    </HTML>


    can anyone do it for me.

    thx in anticipation

    kaleena

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Code this method:
    Code:
    public String addHyphens(String inStr) {
      StringBuffer sb=new StringBuffer();
      String [] splits=inStr.split(","); // split into array of strings using comma as delimiter
      for (int i=0; i<splits.length; i++) {
        if (i > 0) sb.append(",");
        sb.append("'").append(splits[i].trim()).append("'");
      }
      return sb.toString();
    }
    and use it like:

    Code:
    String s="sam,john,undertaker,rock";
    String convertedString=addHyphens(s);
    eschew obfuscation

  3. #3
    Join Date
    Sep 2005
    Posts
    2
    thanks a lot sir.....
    thx for ur valuable help
    Last edited by kaleena; 09-01-2005 at 12:40 PM.

Similar Threads

  1. How to convert a C code into C++
    By kathi in forum C++
    Replies: 3
    Last Post: 04-26-2005, 05:30 PM
  2. Control Arrays in VB.NET
    By Gary Nelson in forum .NET
    Replies: 277
    Last Post: 10-01-2003, 12:00 AM
  3. Replies: 0
    Last Post: 04-11-2002, 06:48 PM
  4. .NET equals Efficiency
    By Kevin in forum .NET
    Replies: 150
    Last Post: 03-04-2002, 05:40 PM
  5. Replies: 0
    Last Post: 04-11-2000, 12:10 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links