文字列内の空白を削除するC#プログラム
以下が文字列であるとしましょう-
StringBuilder str = new StringBuilder("Patience is key!"); 空白を削除するには、replaceメソッドを使用できます。
str.Replace(" ", ""); 完全なコードを見てみましょう。
例
using System;
using System.Text;
class Demo {
static void Main() {
// Initial String
StringBuilder str = new StringBuilder("Patience is key!");
Console.WriteLine(str.ToString());
// Replace
str.Replace(" ", "");
// New String
Console.WriteLine(str.ToString());
Console.ReadLine();
}
} 出力
Patience is key! Patienceiskey!
-
文字列内のすべてのスペースを「%20」に置き換えるC#プログラム
スペースを含むサンプル文字列があります- str ="Hello World !"; C#のReplace()メソッドを使用して、文字列内のすべてのスペースを「%20」に置き換えます- str2 = str.Replace(" ", "%20"); 例 次のコードを実行して、文字列内のすべてのスペースを「%20」に置き換えることができます。 using System; class Demo { static void Main() { String str, str
-
文字列からすべての空白を削除するJavaプログラム
この記事では、文字列からすべての空白を削除する方法を理解します。文字列は、1つ以上の文字を含み、二重引用符(“”)で囲まれたデータ型です。 以下は同じのデモンストレーションです- 入力がであると仮定します − Input string: Java programming is fun to learn. 必要な出力は − The string after replacing white spaces: Javaprogrammingisfuntolearn. アルゴリズム Step 1 - START Step 2 - Declare two strings namely Strin