Write a program in C# Sharp to extract a substring from a given string without using the library function

  • برمجة سي شارب
  • برمجة

Write a program in C# Sharp to extract a substring from a given string without using the library function.
Test Data :
Input the string : This is a test string
Input the position to start extraction :5
Input the length of substring :5
Expected Output :

The substring retrieve from the string is :  is a

الأجوبة

using System;
public class exercise13
{
	public static void Main()
	{
  string str;
  char[] arr1;
  int pos, l, ln, c = 0; 
               Console.Write("\n\nExtract a substring from a given string:\n");
               Console.Write("--------------------------------------------\n");  
               Console.Write("Input the string : ");
               str = Console.ReadLine();	
			   ln=str.Length;
	           arr1 = str.ToCharArray(0, ln);
               Console.Write("Input the position to start extraction :");
               pos= Convert.ToInt32(Console.ReadLine());   
               Console.Write("Input the length of substring :");
               l= Convert.ToInt32(Console.ReadLine()); 	   
 Console.Write("The substring retrieve from the string is : ");
   while (c < l) 
   {
   Console.Write(arr1[pos+c-1]);
      c++;
   }
   Console.Write("\n\n");
 }
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...