0

working with string

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { string a = "Jai Baba Budhpuri ji"; Console.WriteLine(a.Length); Console.WriteLine(a.IndexOf('p')); Console.WriteLine(a.IndexOf('u')); } } } output as below: 20 21 13 11 How should I write code to refer and get the output for u(second placed before r).

2nd Oct 2018, 1:15 AM
kp kalia
kp kalia - avatar
2 Answers
+ 2
In this situation you can use: a.lastIndexOf('u')); If you needed the index of a certain character in between two of its own, you will need to use a loop to go through and get the nth occurrence.
3rd Oct 2018, 12:31 AM
Jerid Derply
Jerid Derply - avatar
0
@Jerid Derply Not working....sir. Error Message: ..\Playground\(18,33): error CS1061: 'string' does not contain a definition for 'lastIndexOf' and no extension method 'lastIndexOf' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?) However thanks for care and concern.
4th Oct 2018, 1:03 AM
kp kalia
kp kalia - avatar