वह स्ट्रिंग सेट करें जिसे आप विभाजित करना चाहते हैं।
string str = "Hello World!";
स्ट्रिंग को अलग-अलग तत्वों में विभाजित करने के लिए split() मेथड का उपयोग करें।
string[] res = str.Split(' ');
C# में स्ट्रिंग को स्ट्रिंग सरणी के तत्वों में विभाजित करने का पूर्ण कोड निम्नलिखित है।
उदाहरण
using System;
class Demo {
static void Main() {
string str = "Hello World!";
string[] res = str.Split(' ');
Console.WriteLine("अलग तत्व:");
foreach (string words in res) {
Console.WriteLine(words);
}
}
}
आउटपुट
यह निम्नलिखित आउटपुट देगा -
अलग तत्व: Hello World!