c# - How do you replace a character in a string with a string? -



c# - How do you replace a character in a string with a string? -

this question has reply here:

c# string replace not work 3 answers

in illustration below have string pipes | separating each segment in string (ie:0123456789). trying replace pipe character string shown in illustration below. how accomplish that?

from understand .replace can back upwards (char,char) or (string, string).

example code:

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace consoleproject { public class programme { public static void main(string[] args) { string val1 = "0123456789|0123456789|0123456789|0123456789|0123456789"; val1.replace('|'.tostring(), "*val1test*"); string val2 = "0123456789|0123456789|0123456789|0123456789|0123456789"; val2.replace("|", "**val2test**"); console.writeline(string.format("{0}{1}","val1: ",val1)); console.writeline(string.format("{0}{1}", "val2: ", val2)); } } }

output console

val1: 0123456789|0123456789|0123456789|0123456789|0123456789 val2: 0123456789|0123456789|0123456789|0123456789|0123456789

if @ definition .replace() returns string - need set variable so:

val1 = val1.replace('|'.tostring(), "*val1test*");

c# asp.net

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -