Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
How to find the first index of a sub-string in a given string
//Rextester.Program.Main is the entry point for your code. Don't change it. //Microsoft (R) Visual C# Compiler version 2.9.0.63208 (958f2354) using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //How to find the first index of a substring in a given string? //use question as given string and find the index of the substring "fir". //Builin array functions and LINQ are not allowed. string strMainString = "How to find the first index of a sub-string in a given string?" ; string srtSubstring = "fir"; int iMainstrLenght = strMainString.Length; int iSubstringLenght = srtSubstring.Length; bool bfound = false; for(int i=0 ;i<=iMainstrLenght-iSubstringLenght;i++) { int j; for(j=0;j<iSubstringLenght;j++) if(strMainString[i+j]!=srtSubstring[j]) break; if(j==iSubstringLenght) { bfound = true; Console.WriteLine("Index is "+i ); } } if(!bfound) Console.WriteLine("No substring found" ); } } }
run
|
edit
|
history
|
help
0
Math 5.81
সদফঘজ্যুয়হতগ্রফেদ
clientdata.cs
The Collatz Conjecture
Using Yield Return to mass copy a Class instance
generic hierarchy1
Planet-D ver. 0.7
Main5.2
Program
Binary Search Tree