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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:41:42+00:00 2026-05-24T23:41:42+00:00

Can I read String Builder line by line? And Get the length of each

  • 0

Can I read String Builder line by line? And Get the length of each line as well.


EDIT:

“I build string in StringBuilder and add “\n” within. And I need to read it again. I need to consider that every “\n” has a new line.“

  • 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-24T23:41:42+00:00Added an answer on May 24, 2026 at 11:41 pm

    Given your edit, it’s as simple as invoking toString() on the StringBuilder instance, and then invoking split("\\n") on the returned String instance. And from there, you’ll have a String array that you can loop through to access each “line” of the StringBuilder instance. And of course, invoke length() on each String instance, or “line” to get its length.


    StringBuilder sb = new StringBuilder();
    sb.append("line 1");
    sb.append("\\n");
    sb.append("line 2");
    
    String[] lines = sb.toString().split("\\n");
    for(String s: lines){
        System.out.println("Content = " + s);
        System.out.println("Length = " + s.length());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that I want to read line-by-line, but I also need
I can read XLS file with this code : string path =@c:\r\1.xlsx; OleDbConnection MyConnection
I can read settings like this, for example: final String mytest = System.getString(this.getContentResolver(), System.AIRPLANE_MODE_ON);
The values in a file are read as string and can be double, string
I read that in Java, String is immutable, so we can't really use toLowerCase
I'm trying to prepend a string a read-only, multi-line TextBox using the following code:
Hi there i am wondering how i can post a urlencoded string and read
How can i check the read/ write permission of the file storing media? ie
You can read this question where I ask about the best architecture for a
I can read unmanaged memory in C# using UnmanagedMemoryStream, but how can I do

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.