0

I need to replace https://9S&Re with https://9S#Re so that I can avoid split logic. My objective is it get key as "user_image" and value as "https://9S&Re". But when I use split with '&' it gives me wrong results. So I am trying for regex pattern which will check between &*& if there is not equals inbetween means there is an ampersand symbol in the one of the query value. Any help is really appreciated.

import java.nio.charset.Charset;
    import java.util.HashMap;
    import java.util.List;

    import org.apache.http.NameValuePair;
    import org.apache.http.client.utils.URLEncodedUtils;

    public class OAuthTest {

        public static void main(String[] args) {
            try {
                //HashMap paramHashMap=new HashMap();           
                List<NameValuePair> args2= URLEncodedUtils.parse("tool=canvas&tool_guid=8314&user_image=https://9S&Re&launch_presentation_document_target=iframe", Charset.forName("UTF-8"));
                for (NameValuePair arg:args2)
                    System.out.println(arg.getName()+"="+arg.getValue().replaceAll("#","&"));

            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }

1 Answer 1

1

In the for loop, are you trying to replace & with #? Your arguments are switched.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.