Results 1 to 5 of 5
  1. #1
    alexandra12 is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

    Default trying to implement java . replace

    I have an array coming in
    "status": [ "1", "2", "3" ],

    I need to add &p_status= before each number
    so for example the result should read &p_status=1&p_status=2&p_status=3

    here is part of my code

    var graphURL = this.getURL("C10", "Work")
    + "&p_start=" + message.start
    + "&p_end=" + message.end
    + "&p_summarize=" +message.summarize;


    var types = message.status[0].toString().replace("/,/g", '&p_status=');
    for (i = 0; i < types.length; i++)
    //need to add the &p_status first because the .replace only works after the first ,
    graphURL += "&p_status=" + types[i];


    currently my result for the parameters for the above code is
    &p_start=2011-06-22-00.00.00&p_end=2011-07-22-23.59.59&p_summarize=daily&p_status=1


    Any help would be greatly appreciated.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    Your post is very confusing and makes little sense to me, especially when you use non-Java code.

    If all you want to do is add "&p_status=" before each value then you can use String concatenation.
    Java Code:
    String[] status = {"1", "2", "3"};
    String prefix = "&p_status=";
    for(String s : status) {
        System.out.println(prefix + s);
    }
    If you want to store the formatted String then simply assign the result of the concatenation to a variable, array or Collection.

  3. #3
    alexandra12 is offline Member
    Join Date
    Jul 2011
    Posts
    36
    Rep Power
    0

    Default

    Thanks for that Junky. I actually meant to say that it was Javascript.All I want to do is put &p_status in front of the numbers.. I will try your code.

    Thanks again for the help

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    Quote Originally Posted by alexandra12 View Post
    I actually meant to say that it was Javascript.
    Well this is a Java forum not a Javascript forum.

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    11

    Default

    Java is to JavaScript as Ham is to Hamster.

    Entirely different beasts, a JavaScript forum is where you want to look.

Similar Threads

  1. Java String Replace
    By aham in forum New To Java
    Replies: 4
    Last Post: 05-17-2011, 08:46 AM
  2. Replace an Xml attribute/element value via Java
    By j_kathiresan in forum New To Java
    Replies: 3
    Last Post: 05-12-2011, 03:57 PM
  3. Replies: 9
    Last Post: 08-31-2010, 05:21 AM
  4. is there anyway to replace java.IO
    By nobody58 in forum Advanced Java
    Replies: 1
    Last Post: 03-19-2010, 02:19 PM
  5. Replies: 2
    Last Post: 08-18-2008, 02:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •