स्ट्रिंग सेट करें
string s = "Tom Cruise";
अब मान लें कि आपको उपस्ट्रिंग "Tom" ढूंढनी है, फिर Contains() विधि का उपयोग करें।
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!