Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,924 questions

51,857 answers

573 users

How to search string from the right (reverse) in C#

3 Answers

0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string s = "Star Wars is great movie";

                int i = s.LastIndexOf('i');
	            if (i != -1)
	            {
	                Console.WriteLine(i);
	                Console.WriteLine(s.Substring(i));
	            }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:
  
22
ie
 
*/


answered Mar 28, 2015 by avibootz
edited Feb 7, 2016 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string s = "Star Wars is great movie. Star Trek is also a great movie";

                int i = s.LastIndexOf("great");
	            if (i != -1)
	            {
	                Console.WriteLine(i);
	                Console.WriteLine(s.Substring(i));
	            }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:
  
46
great movie
 
*/


answered Mar 28, 2015 by avibootz
edited Feb 7, 2016 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string s = "Star Wars is GREAT movie. Star Trek is also a Great movie";

                // ignor the case
                int i = s.LastIndexOf("great", StringComparison.OrdinalIgnoreCase); 
                if (i != -1)
                {
                    Console.WriteLine(i);
                    Console.WriteLine(s.Substring(i));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:
   
46
Great movie
  
*/


answered Mar 28, 2015 by avibootz
edited Feb 7, 2016 by avibootz

Related questions

1 answer 251 views
3 answers 257 views
1 answer 159 views
1 answer 76 views
76 views asked Mar 3, 2024 by avibootz
1 answer 146 views
...