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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:17:51+00:00 2026-06-17T04:17:51+00:00

I am trying to replace string but due to few matching words it is

  • 0

I am trying to replace string but due to few matching words it is replacing both the string.

Val1 = "CASE WHEN [" + isParent + "] = 0 THEN 'False' WHEN [" + isParent + "] = 1 THEN 'True' END ";
Val2 = "CASE WHEN [" + isChild + "] = 0 THEN 'False' WHEN [" + isChild  + "] = 1 THEN 'True' END ";
val3 = str.Replace("IS_PARENT", Val1 ).Replace("IS_CHILD", val2);

in my

str = "IS_PARENT, IS_CHILD_WITH_ROLE, IS_CHILD"; 

IS_CHILD is coming in two place so it is replacing both IS_CHILD.

I want to replace only exact word IS_CHILD.

how to do that?

  • 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-17T04:17:52+00:00Added an answer on June 17, 2026 at 4:17 am

    You can use Regex.Replace

    string newString = Regex.Replace(str, @"\bIS_CHILD\b", replacedText);
    

    EDIT:
    If you want to replace IS_PARENT with the same criteria as IS_CHILD (replacing the whole word only)

    string  newString = Regex.Replace(newString, @"\bIS_PARENT\b", "NEW TEXT");
    newString = Regex.Replace(str, @"\bIS_CHILD\b", replacedText);
    

    OR (This is not optimized and in the answer because it is one way to replace a single word)

    You can split the string based on the space, and then use string.Join to create a new string after replacing the complete word.

    string str = "IS_PARENT, IS_CHILD_WITH_ROLE, IS_CHILD";
    string replacedText = "SomeThing";
    string newString = string.Join(" ", str.Split()
                                           .Select(r => r == "IS_CHILD" ? replacedText : r));
    

    New String will be:

    IS_PARENT, IS_CHILD_WITH_ROLE, SomeThing
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to replace a large string in groovy. But can't get it
im trying make one replace in string from a array but this dont work
Trying to replace a string, but it seems to only match the first occurrence,
I'm trying to replace a string with another one by using stringByReplacingOccurrencesOfString, but for
I am trying to replace a string with another string, but the greedy nature
I'm trying to replace a special character (^) in javascript with string.replace but am
I am trying to replace every character from a string with it's opposite but
I am trying to insensitive replace string, so I'm using str_ireplace() but it does
This is the string i'm trying to replace white spaces between the words with
I'm trying to do a Javascript replace (to remove some words from a string)

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.