c# - string.Replace() searching for string + ANY CHAR + string -


i'm searching giant .json file, , trying replace text. here exact situation i'm working with.

string json = (a json file string of text) string result = null; result = json.replace("\"$id\":\"7\",\"questionnumber", "replacment text"); 

i want search whole json file , replace every occurance replacment text. however, want search whole file

"\"$id\":\"7\",\"questionnumber" 

where, instead of number "7", can number. know need use regex i'm new regex , i'm not sure how go passing regex stuff string.replace parameters.

also major caveat here, need add "7", whatever number happens per replacement, "replacement text" string.

use regex.replace().

//using system.text.regularexpressions; regex regex = new regex("\"\\$id\":\"(\\d+)\",\"questionnumber"); string result = regex.replace(json, "replacement text $1"); 

this should turn text such as

"$id":"8","questionnumber "$id":"3","questionnumber 

into

replacement text 8 replacement text 3 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -