Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6953227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:27:08+00:00 2026-05-27T14:27:08+00:00

I have a string like (&(objectclass=${abc})(uid=${xyz})) How can I search ${abc} and ${xyz} and

  • 0

I have a string like

(&(objectclass=${abc})(uid=${xyz}))

How can I search ${abc} and ${xyz} and replace with another strings. There can be any number of occurence of such substrings i.e.${abc} in main string. I was thinking of string.indexOf( but that could be messy. Any best approach?

${abc} will be replaced by another string abc. I will get them from some other parameters.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:27:08+00:00Added an answer on May 27, 2026 at 2:27 pm

    I would use String.indexOf(String sep, int start) in a loop repeatedly to copy text and values to a StringBuilder.


    Something like

    public static void main(String... args) throws IOException {
        Map<String, String> map = new LinkedHashMap<>();
        map.put("abc", "ABC");
        map.put("xyz", "XYZ");
        printSubstitue("nothing to change", map);
        printSubstitue("(&(objectclass=${abc})(uid=${xyz})(cn=${cn})(special='${'))", map);
    }
    
    private static void printSubstitue(String text, Map<String, String> map) {
        String text2 = subtitue(text, map);
        System.out.println("substitue( "+text+", "+map+" ) = "+text2);
    }
    
    public static String subtitue(String template, Map<String, String> map) {
        StringBuilder sb = new StringBuilder();
        int prev = 0;
        for (int start, end; (start = template.indexOf("${", prev)) > 0; prev = end + 1) {
            sb.append(template.substring(prev, start));
            end = template.indexOf('}', start + 2);
            if (end < 0) {
                prev = start;
                break;
            }
            String key = template.substring(start + 2, end);
            String value = map.get(key);
            if (value == null) {
                sb.append(template.substring(start, end + 1));
            } else {
                sb.append(value);
            }
    
        }
        sb.append(template.substring(prev));
        return sb.toString();
    }
    

    prints

    substitue( nothing to change, {abc=ABC, xyz=XYZ} ) = nothing to change
    substitue( (&(objectclass=${abc})(uid=${xyz})(cn=${cn})(special='${')), {abc=ABC, xyz=XYZ} ) 
         = (&(objectclass=ABC)(uid=XYZ)(cn=${cn})(special='${'))
    

    It gets messy if you want to support nested ${ } values. 😉

    abc123=ghi123
    abc${xyz}=def${xyz}
    
    (&(objectclass=${abc${xyz}})(uid=${xyz}))
    

    I would suggest you keep it simple if you can. 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: abc=foo&def=%5Basf%5D&xyz=5 How can I convert it into a
I have a string like this: &lt;![CDATA[&lt;ClinicalDocument&gt;rest of CCD here&lt;/ClinicalDocument&gt;]]&gt; I'd like to replace
If I have a string like so: Name=Irwin&Home=Caribbean&Preference=Coffee is there a method in C#
I have a string like this : oauth_token=1%2F7VDUGD4tKIqSu4jX4DoeCRD1KbqqgTxFnFFliVgbSss&oauth_token_secret=Rk%2FwejMIg6t%2BFphvRd%2BZ5Wkc How can I extract the two
I have a string like: string originalStringBefore = http://www.abc.com?a=||ThisIsForRndNumber||&qq=hello&jj=||ThisIsForRndNumberAlso||; I want every string which
I have a string where special characters like ' or or & (...) can
I have a string like this, sidePanel[]=1&sidePanel[]=2&sidePanel[]=4 And if I need to add another
Let's presume that I have string like '=&?/;#+%' to be a part of my
I have a string like so: http://www.youtube.com/v/Nnp82q3b844&hl=en_US&fs=1& and I want to extract the Nnp82q3b844
I have a url string like this: http://www.google.com/cse?cx=017840637368510444960:ny1lmky7r-0&client=google-csbe&output=xml_no_dtd&q=simon+g I need to send this url

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.