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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:25:06+00:00 2026-06-07T17:25:06+00:00

I have been out of touch with programming for a while. I have some

  • 0

I have been out of touch with programming for a while. I have some strings I want to format. They look like this:

,SUM(CASE WHEN [Level] IN('4') AND Program = 1 THEN 1 ELSE 0 END) as CNT1
,SUM(CASE WHEN [Level] IN('3') AND Program = 1 THEN 1 ELSE 0 END) as CNT2
,SUM(CASE WHEN [Level] IN('2') AND Program = 1 THEN 1 ELSE 0 END) as CNT3
,SUM(CASE WHEN [Level] IN('1') AND Program = 1 THEN 1 ELSE 0 END) as CNT4
,SUM(CASE WHEN [Level] IN('0') AND Program = 1 THEN 1 ELSE 0 END) as CNT5

I want to take this and change it to

,CNT1 = SUM(CASE WHEN [Level] IN('4') AND Program = 1 THEN 1 ELSE 0 END) 
,CNT2 = SUM(CASE WHEN [Level] IN('3') AND Program = 1 THEN 1 ELSE 0 END) 
,CNT3 = SUM(CASE WHEN [Level] IN('2') AND Program = 1 THEN 1 ELSE 0 END) 
,CNT4 = SUM(CASE WHEN [Level] IN('1') AND Program = 1 THEN 1 ELSE 0 END) 
,CNT5 = SUM(CASE WHEN [Level] IN('0') AND Program = 1 THEN 1 ELSE 0 END) 

right now I have a multiline textbox that I paste the strings in. I want to click a button and have it formatted into a second textbox.

This is what I’ve tried so far. but I am not sure what string functions to use format it the way i want.

            List<String> Items = new List<string>();
            string frTxt;
            foreach (string lne in txtM.Lines)
            {
                frTxt = "";
                frTxt = lne;

            }  

where txtM is the multiline textbox. If I do Console.WriteLine(lne); in the loop, it loops through successfully.

  • 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-07T17:25:08+00:00Added an answer on June 7, 2026 at 5:25 pm

    Assuming the format is always

    ,<text_1> as <text_2>

    This the following will transform it to:

    ,<text_2> = <text_1>

    txtM.Lines = txtM.Lines.Select(l => Regex.Replace(l, ",(.+) as (.+?)$", ",$2 = $1")).ToArray();
    

    Explanation of regex:

    • The “,” and ” as ” match those exact strings
    • “(.+)” greedy-matches at least one character, and captures it as the first group
    • “(.+?)” non-greedy-matches at least one character and captures it as the second group
    • “$” matches the end of the line

    As a result of combining the greedy and non-greedy matching, we force the ” as …” to be the last occurrence (so if the string happens to contain ” as ” somewhere in it, that won’t matter). By adding the “$” we ensure that the second capture takes everything to the end of the line (otherwise as it’s a non-greedy match it would match just the first character after ” as “, which isn’t what we want).

    The replacement simply constructs the new string using the two groups captured by the regex, adding the “=”. We also manually add back the “,” at the beginning because our regex matches on it and so it will be replaced by the replacement string. (This can be overcome but would probably make the regex more complex).

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

Sidebar

Related Questions

I have been out of touch with Algorithms for a while and have start
I have been checking out some of the possible timers lately, and System.Threading.Timer and
I have been trying out Cassandra and need some help in understanding a few
I have been trying to figure out why I am getting this problem and
I have been developing android apps out of hobby and fun. I want to
I'm quite new to openGL and I have been trying out some sample codes
I have been trying to strip out some data from HTML files. I have
I want to write a rule that looks something like this: foo.out: (out of
We have been facing Out of Memory errors in our App server for sometime.
I have been trying out the MoreLikeThis Bundle to bring back a set of

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.