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 8946975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:37:53+00:00 2026-06-15T12:37:53+00:00

How does one format the following: From this: 1: My street 2: 1232321 3:

  • 0

How does one format the following:

From this:

1: My street
2: 1232321
3: Hello there world!
4: A really really really long word!

To this:

1:                           My street
2:                             1232321
3:                  Hello there world!
4:   A really really really long word!

I think it has something to do with String.format() and a bunch of random chars in it!

  • 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-06-15T12:37:55+00:00Added an answer on June 15, 2026 at 12:37 pm

    You can first split your string to get 1: and My Street separately, and then format them: –

    String str = "1: My street";
    String str2 = "3: Hello there world!";
    
    String[] arr = str.split("(?<=:) ");
    String[] arr2 = str2.split("(?<=:) ");
    
    System.out.printf("%s%30s\n", arr[0], arr[1]);
    System.out.printf("%s%30s", arr2[0], arr2[1]);
    

    Output : –

    1:                     My street
    3:            Hello there world!
    

    You can do this with String#substring method also, to get the two parts separately.

    System.out.printf("%s%30s\n", str.substring(0, 2), str.substring(3));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how to write the following in a neater, one line format?
This is really two questions one leading into the other. Firstly what does 'Permission
This following script almost does what I need. What I'm trying to do is
Using the following steps: (I have checked this similar post , which does not
I'm working on a utility to convert excel file from one format to another.
if a string has this predicted format: value = hello and good morning Where
There is something wrong with the script that copies last posts from one Wordpress
I have a large string accepted from TCP listner which is in following format
I am trying to write XSLT to transform my XML from one format to
does one perform better over the other in terms of indexing/quering etc ? e.g.

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.