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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:51:26+00:00 2026-06-14T06:51:26+00:00

I am building up a string of data using substring. The format of the

  • 0

I am building up a string of data using substring. The format of the data I want is

[1,2,3,4,5,6,7,8,9,10]

So I am building it up as follows

StringBuilder sb = new StringBuilder();
sb.append("1,");
sb.append("2,");
sb.append("3,");
.
.
.

The problem I run into is when I want to trim the final , before adding the closing ].

I could do

sb.ToString();
sb.Substring(0, (sb.Length - 1));
sb += "]";

But using the += is not very efficient as this creates a new string. Is there a better way of doing this?

  • 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-14T06:51:27+00:00Added an answer on June 14, 2026 at 6:51 am

    The easiest is to use -= on the StringBuilder‘s Length since it’s writable:

    sb.Length -= 1; // removes the last char
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using a c# asp.net page, building a SQL query string to run against an
I am building a .NET application that given a connection string, at run time,
I'm building a thesaurus using a HashMap <String,ArrayList<String>> to hold words and their synonyms
I am working on string maniplations using regex. Source: string value = @/webdav/MyPublication/Building%20Blocks/folder0/folder1/content_1.xml; output
I had some existing VBA code that was building queries using string concatenation. I
I'm trying to insert non-latin data into sqlite database using bind variables using System.Data.SQLite.
I am building a WCF data service (with .net 4.5 VS 2012) using Reflection
I'm building a general purpose data translation tool for internal enterprise use, using Java
I'm building a data seeder module that looks for all models using introspection and
I have a class that is building some HTML using data stored in an

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.