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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:47:13+00:00 2026-06-01T02:47:13+00:00

I have a string as below. string data = A := B;\nC:=D; The string

  • 0

I have a string as below.

string data = "A := B;\nC:=D";

The string has to be replaced with SET statement as below.

data = "SET A=B;\nSET C=D"

It should replace := with =and insert aSET` statement.

I came out with an algorithm as below but it’s not working when I have multiple :=.

Is there any other easiest and efficient way to handle this? Perhaps using RegEx?

private string AddSETStatement(string script)
{
        script = script.Replace(": =", ":=");
        script = script.Replace(":=", ":= ");
        script = script.Replace(" :=", ":= ");
        int found = script.IndexOf(":=");
        while (found > -1)
        {
            int foundspace = -1;
            for (int index = found; index >= 0; index--)
            {
                string temp = script.Substring(index, 1);
                if (temp == " ")
                {
                    foundspace = index;
                    break;
                }
            }
            script = script.Remove(found, 1);
            if (foundspace == -1)
            {
                script = "SET " + script;
            }
            else
            {
                script = script.Insert(foundspace, " SET ");
            }
            found = script.IndexOf(":=");
        }

        return script.Trim();
}

Any help would be appreciated.

  • 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-01T02:47:15+00:00Added an answer on June 1, 2026 at 2:47 am

    I’ve tested this and I think this is the command that matches your requirement as you’ve coded your algorithm (which can be replaced with one line of code):

    script = System.Text.RegularExpressions.Regex.Replace(script, 
         @"([A-Z]{1})[\s]{0,1}:[\s]{0,1}=[\s]{0,1}([A-Z]{1})", "SET $1=$2", 
         System.Text.RegularExpressions.RegexOptions.Multiline);
    

    Just in case you actually use more than one space between and around := you can use this instead:

    script = System.Text.RegularExpressions.Regex.Replace(script,
         @"([A-Z]{1})[\s]*:[\s]*=[\s]*([A-Z]{1})", "SET $1=$2", 
         System.Text.RegularExpressions.RegexOptions.Multiline);
    

    This turns this:

    A := B;
    C:=D
        E: =F
    G : = H
      I   :   =   K;
    

    Into this:

    SET A=B;
    SET C=D
        SET E=F
    SET G=H
      SET I=K;
    

    And one more which handles variable names that are bother upper and lower case and contain numbers:

    script = System.Text.RegularExpressions.Regex.Replace(script,
         @"([A-Za-z0-9]+)[\s]*:[\s]*=[\s]*([A-Za-z0-9]{1})", "SET $1=$2", 
         System.Text.RegularExpressions.RegexOptions.Multiline);
    

    Turns this:

    Alpha1 := Bravo2;
    Char3le:=Delta9
        E1ch3: =Foxt343
    golf : = h1
      I3   :   =   k;
    

    Into:

    SET Alpha1=Bravo2;
    SET Char3le=Delta9
        SET E1ch3=Foxt343
    SET golf=h1
      SET I3=k;
    

    At least one those or a combination of those should be able to do the work for you.

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

Sidebar

Related Questions

I have String vector that has data set look like below. vector<string> result; <index>
I have a txt file which has data in the below format: int string
I have the below String assignment statement String items[] = line.split(\,\,15); String fileNamet =
I have a string which has the below content String msg = The variables
Say I have a Java String which has xml data like so: String content
I have an xml string below that I've turned into an object using $content
I have a string of below type. [test1,3,(257,305,435,900)] Now i want to split this
I have an alphanumeric string like below, $string_1 = a4nas60dj71wiena15sdl1131kg12b and would like to
i have an array below string stringArray = new stringArray[12]; stringArray[0] = 0,1; stringArray[1]
I have the code below: string SQL = select * from + TableName; using

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.