C# 程式從字串中替換特殊字元
假設我們的字串是 -
string str = "abcd$ef$gh";
使用 Replace() 方法替換特殊字元。
string res = str.Replace('$', 'k');下面的完整程式碼用於從字串中替換字元 -
例項
using System;
public class Program {
public static void Main() {
string str = "abcd$ef$gh";
Console.WriteLine("Initial string = " + str);
string res = str.Replace('$', 'k');
// after replacing
Console.WriteLine("Replaced string = " + res.ToString());
}
}輸出
Initial string = abcd$ef$gh Replaced string = abcdkefkgh
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP