स्ट्रिंग सेट करें
string s = "Tom Cruise";
अब मान लें कि आपको "टॉम" सबस्ट्रिंग खोजने की आवश्यकता है, फिर इसमें शामिल हैं () विधि का उपयोग करें।
if (s.Contains("Tom") == true) {
Console.WriteLine("Substring found!");
} एक स्ट्रिंग से सबस्ट्रिंग कैसे खोजें, यह जानने के लिए निम्नलिखित कोड है -
उदाहरण
using System;
public class Demo {
public static void Main() {
string s = "Tom Cruise";
if (s.Contains("Tom") == true) {
Console.WriteLine("Substring found!");
} else {
Console.WriteLine("Substring not found!");
}
}
} आउटपुट
Substring found!