C# में एक स्ट्रिंग को विभाजित करने और जोड़ने के लिए, स्प्लिट () और ज्वाइन () विधि का उपयोग करें। मान लें कि निम्नलिखित हमारी स्ट्रिंग है -
string str = "This is our Demo String";
स्ट्रिंग को विभाजित करने के लिए, हम विभाजन () विधि का उपयोग करेंगे -
var arr = str.Split(' '); अब शामिल होने के लिए, join() विधि का उपयोग करें और शेष स्ट्रिंग में शामिल हों। यहां, हमने स्किप () विधि का उपयोग करके स्ट्रिंग के हिस्से को छोड़ दिया है -
string rest = string.Join(" ", arr.Skip(1)); उदाहरण
आप स्ट्रिंग को विभाजित करने और जोड़ने के लिए निम्नलिखित कोड को C# में चलाने का प्रयास कर सकते हैं।
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo {
class MyApplication {
static void Main(string[] args) {
string str = "This is our Demo String";
var arr = str.Split(' ');
// skips the first element and joins rest of the array
string rest = string.Join(" ", arr.Skip(1));
Console.WriteLine(rest);
}
}
} आउटपुट
is our Demo String