0

I have a string

 var query =  select id, Details.Id, Details.Info.Id from DetailsItem

I want to replace Details with [Details], so I am using

query.Replace(" Details", " [Details]");

I get the following

select id, [Details].Id, [Details].Info.Id from [Details]Item

but it replaces DetailsItem which I dont want. How can I only replace if the word is Details only?

0

1 Answer 1

2

You should use Regex.Replace() method with word boundary i.e \b,

string queryResult = Regex.Replace(query, @"\bDetails\b", "[Details]", RegexOptions.None);  

.Try Online

Sign up to request clarification or add additional context in comments.

2 Comments

Works if I use @"\bDetails\b" (without space before 'D')
tried it without the \b and it didnt work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.