প্রথমে একটি স্ট্রিং সেট করুন −
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("স্ট্রিং...\n" + str);
string[] myStr = str.Split(' ');
Console.WriteLine("\nভাগ করা স্ট্রিং...");
foreach (string ch in myStr) {
Console.WriteLine(ch);
}
}
}
আউটপুট
স্ট্রিং... Science and Mathematics ভাগ করা স্ট্রিং... Science and Mathematics