C#
 Computer >> コンピューター >  >> プログラミング >> C#

スペースで文字列を分割するC#プログラム


まず、文字列を設定します-

string str = "Science and Mathematics";

次に、Split()メソッドを使用して、スペースが発生する場所を分割します-

str.Split(' ')

以下は完全なコードです-

using System;
using System.Linq;
using System.IO;
class Program {
   static void Main() {
      string str = "Science and Mathematics";
      Console.WriteLine("String...\n"+str);
      string[] myStr = str.Split(' ');
      Console.WriteLine("\nSplitted String...");
      foreach (string ch in myStr) {
         Console.WriteLine(ch);
      }
   }
}

出力

String...
Science and Mathematics

Splitted String...
Science
and
Mathematics

  1. 文字列を分割して結合するPythonプログラム?

    Pythonプログラムは、文字列の結合と文字列の分割のための組み込み関数を提供します。 split Str.split() join Str1.join(str2) アルゴリズム Step 1: Input a string. Step 2: here we use split method for splitting and for joining use join function. Step 3: display output. サンプルコード #split of string str1=input(Enter first String with space :: ) prin

  2. Pythonで区切り文字strによって文字列を分割する方法は?

    PythonのStringクラスには、オプションの引数として区切り文字を受け取るsplit()というメソッドがあります。デフォルトの区切り文字は空白です。次のように使用できます: >>> 'aa-ab-ca'.split('-') ['aa', 'ab', 'ca'] >>> 'abc mno rst'.split(' ') ['abc', 'mno', 'rst'] この操作に正規表現を使用するこ