কম্পিউটার

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


C#-এ String.IndexOf() পদ্ধতিটি এই উদাহরণের মধ্যে একটি নির্দিষ্ট ইউনিকোড অক্ষর বা স্ট্রিংয়ের প্রথম ঘটনার শূন্য-ভিত্তিক সূচক খুঁজে পেতে ব্যবহৃত হয়।

সিনট্যাক্স

সিনট্যাক্স নিম্নরূপ -

public int IndexOf (string val);

উপরে, ভ্যাল হল খুঁজে পাওয়ার স্ট্রিং।

উদাহরণ

আসুন এখন একটি উদাহরণ দেখি -

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("Index of character 'o' is str1 = " + str1.IndexOf("o"));
      Console.WriteLine("\nString 2 = "+str2);
      Console.WriteLine("HashCode of String 2 = "+str2.GetHashCode());
      Console.WriteLine("Index of character 'o' is str2 =" + str2.IndexOf("o"));
      bool res = str1.Contains(str2);
      if (res)
         Console.WriteLine("Found!");
      else
         Console.WriteLine("Not found!");
   }
}

আউটপুট

এটি নিম্নলিখিত আউটপুট −

তৈরি করবে
String 1 = Jacob
HashCode of String 1 = -790718923
Index of character 'o' is str1 = 3
String 2 = John
HashCode of String 2 = -1505962600
Index of character 'o' is str2 =1
Not found!

উদাহরণ

এখন আরেকটি উদাহরণ দেখা যাক -

using System;
public class Demo {
   public static void Main(String[] args) {
      string str1 = "Kevin";
      string str2 = "Evin";
      Console.WriteLine("String 1 = "+str1);
      Console.WriteLine("HashCode of String 1 = "+str1.GetHashCode());
      Console.WriteLine("Index of character 'k' in str1 = " + str1.IndexOf("k"));
      Console.WriteLine("\nString 2 = "+str2);
      Console.WriteLine("HashCode of String 2 = "+str2.GetHashCode());
      Console.WriteLine("Index of character 'k' in str2 =" + str2.IndexOf("k"));
      bool res = str1.Contains(str2);
      if (res)
         Console.WriteLine("Found!");
      else
         Console.WriteLine("Not found!");
   }
}

আউটপুট

এটি নিম্নলিখিত আউটপুট −

তৈরি করবে
String 1 = Kevin
HashCode of String 1 = -768104063
Index of character 'k' in str1 = -1
String 2 = Evin
HashCode of String 2 = 1223510568
Index of character 'k' in str2 =-1
Not found!

  1. C# এ DateTime.ToLongTimeString() পদ্ধতি

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

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

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