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

  • Home
  • SEARCH
  • 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 3722418
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:53:51+00:00 2026-05-19T05:53:51+00:00

dear all, i have a string like this, …1name: john, 2name: lice, 3name: mike….

  • 0

dear all, i have a string like this, “…1name: john, 2name: lice, 3name: mike…”. i want to output its substring “1name: john”. its position in the string is not fixed. i also use the substring method but can not get it. so could you give me a help.

thank you.

  • 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-19T05:53:53+00:00Added an answer on May 19, 2026 at 5:53 am
    String s = str.split(",")[n].trim();
    

    I suggest making a map if the position is random:

    Map<Integer, String> m = new HashMap<Integer, String>();
    for (String s : str.split(",")) {
       s = s.trim();
       int keyvalstart = -1;
       for (int i = 0; i < s.length(); i++) {
          if (!Character.isDigit(i)) {
             keyvalstart = i;
             break;
          }
       }
       if (keyvalstart == -1) continue;
       String s_id    = s.substring(0, keyvalstart - 1);
       String keyvals = s.substring(keyvalstart);
       int    id      = Integer.parseInt(s_id);
       m.put(id, keyvals);
    }
    

    The map will thus contain a list of person IDs to their respective value strings. If you wish to store names only as value elements of the map:

    Map<Integer, String> m = new HashMap<Integer, String>();
    for (String s : str.split(",")) {
       s = s.trim();
       int keyvalstart = -1;
       for (int i = 0; i < s.length(); i++) {
          if (!Character.isDigit(i)) {
             keyvalstart = i;
             break;
          }
       }
       if (keyvalstart == -1) continue;
       String s_id     = s.substring(0, keyvalstart - 1);
       int    id       = Integer.parseInt(s_id);
       String keyvals  = s.substring(keyvalstart);
       int    valstart = keyvals.indexOf("name: ") + "name: ".length();
       String name     = keyvals.substring(valstart);
       m.put(id, name);
    }
    

    It’d be easier to use a StringTokenizer in the second example for the key=value pairs if you want to store more data, but I don’t know what your delimiter is. You’d also need to store objects as values of the map to store the info.

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

Sidebar

Related Questions

Dear all, my issue is this. I have like the alert box to display
Dear All, I have 2 input string 1)stack,over,flow 2)stack/over,flow,com I would like to print
Dear all,Now i have this question in my java program,I think it should be
dear all..i have this code: <script> var str=KD-R435MUN2D; var matches=str.match(/(EE|[EJU]).*(D)/i); if (matches) { var
dear all..i have this data inside DB: line model serial fa01 kd-g335ud 105x0001 fa01
dear all..i have a textfield. i want after i have typed identity number inside
dear all..i have a table it looks like: Name version DDX 01 DTX 05
I have a text file of e-mails like this: 10:info@example.com;dev@example.com 12:john@host.com; George <g.top@host.com> 43:jim.p@web.com.;sue-allen@web.com
dear all.. i have a DB which built use Mysql. for this case, i
Dear All, i have a txt file like: --start-- jeff --end-- --start-- sophya --end--

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.