কম্পিউটার

C# String.Contains() পদ্ধতি


C#-এ String.Contains() পদ্ধতিটি এই স্ট্রিংয়ের মধ্যে একটি নির্দিষ্ট সাবস্ট্রিং আছে কিনা তা নির্দেশ করে একটি মান ফেরত দিতে ব্যবহৃত হয়।

সিনট্যাক্স

public bool Contains (string val);

উপরে, ভ্যাল হল অনুসন্ধান করার জন্য স্ট্রিং।

উদাহরণ

using System;
public class Demo {
   public static void Main(String[] args) {
      string str1 = "Akon";
      string str2 = "Ak";
      Console.WriteLine("String 1 = "+str1);
      Console.WriteLine("HashCode of String 1 = "+str1.GetHashCode());
      Console.WriteLine("String 2 = "+str2);
      Console.WriteLine("HashCode of String 2 = "+str2.GetHashCode());
      Console.WriteLine("String 1 is equal to String 2: {0}", str1.Equals(str2));
      Console.WriteLine("Does String 1 has String 2 = "+str1.Contains(str2));
   }
}

আউটপুট

String 1 = Akon
HashCode of String 1 = 416613838
String 2 = Ak
HashCode of String 2 = -839927841
String 1 is equal to String 2: False
Does String 1 has String 2 = True

উদাহরণ

using System;
public class Demo {
   public static void Main(String[] args) {
      string str1 = "Jacob";
      string str2 = "John";
      Console.WriteLine("String 1 = "+str1);
      Console.WriteLine("HashCode of String 1 = "+str1.GetHashCode());
      Console.WriteLine("String 2 = "+str2);
      Console.WriteLine("HashCode of String 2 = "+str2.GetHashCode());
      bool res = str1.Contains(str2);
      if (res)
         Console.WriteLine("Found!");
      else
         Console.WriteLine("Not found!");
   }
}

আউটপুট

String 1 = Jacob
HashCode of String 1 = -790718923
String 2 = John
HashCode of String 2 = -1505962600
Not found!

  1. C# String.PadRight পদ্ধতি

  2. C# Linq এর মধ্যে রয়েছে পদ্ধতি

  3. C# SingleorDefault() পদ্ধতি

  4. স্ট্রিং Join() পদ্ধতি