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

The Archive Base Latest Questions

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

I have the following string: string input = 2 1; It is 2 spaces

  • 0

I have the following string:

string input = "  2  1";

It is 2 spaces followed by a 2 and then 2 more spaces followed by a 1. I want to do a replace on it, but I only want to replace the spaces between the 2 and the 1 with 0’s and I do not want to use RegEx if possible?

The end result should look like this:

string result = "  2001";

20 340400 1 – 20-34-04-00-00001.0-0000.00

20 340400 500 – 20-34-04-00-00500.0-0000.00

20 340900 C – 20-34-09-00-0000C.0-0000.00

20 3435OG 1 1 – 20-34-35-OG-00001.0-0001.00

20 3435OG 2 10 – 20-34-35-OG-00002.0-0010.00

20 3435OG A – 20-34-35-OG-0000A.0-0000.00

20 3436AA 1 4A – 20-34-36-AA-00001.0-0004.A

20 3436AA 2 10B – 20-34-36-AA-00002.0-0010.B

20 353100 268 – 20-35-31-00-00268.0-0000.00

20G3402AI 1 401 – 20G-34-02-AI-00001.0-0004.01

20G3403AI 7 1 – 20G-34-03-AI-00007.0-0001.00

20G3416MK 1701 – 20G-34-16-MK-00000.0-0017.01

21 3410OM 148 – 21-34-10-OM-00000.0-0147.00

A few things I have noticed is that the first 4 parts are put together, most of the spaces and decimals are removed. I have had success without regex in most cases, but it fails for some.

  • 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-14T09:16:52+00:00Added an answer on June 14, 2026 at 9:16 am

    How about:

    static string ReplaceSpacesWithZerosExceptLeading(string s)
    {
        return s.TrimStart(' ').Replace(' ', '0').PadLeft(s.Length);
    }
    

    This will remove the leading spaces, then replace the rest with zeros, then put the leading ones back on.

    EDIT: Never mind, this answer already exists…

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

Sidebar

Related Questions

I have the following input: string txt = i am a string I want
Hi I have the following date as String format. Input 2010-04-20 05:34:58.0 Output I
I have following problem: Input String 1 : A[SPACE]B[SPACE]C[SPACE][SPACE]D[SPACE][SPACE]E Input String 2 : 1-
So, I want to replace all & in the following string with a single
A have the following input string: string input = Ta005000000000000000000Tb001700000000000000000Sa005000000000000000000 + Sb002500000000000000000F 00000000000000000I 00000000000000000N
I have the following requirements for validating an input field: It should only contain
I have following string: Test, User < test@test.com >, Another, Test < another@test.com >,
I have following situation: String a = A Web crawler is a computer program
I have the following string arrays: var myArray1 = new string[] {A, B, C};
I have the following: string test = CustomerNumber; or string test2 = CustomerNumberHello; the

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.