Advertisement
Gillito

Untitled

Jun 4th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication30
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("input yor first split char: ");
  14.             ConsoleKeyInfo usrKey1 = Console.ReadKey();
  15.             Console.WriteLine("input yor second split char: ");
  16.             ConsoleKeyInfo usrKey2 = Console.ReadKey();
  17.             Console.WriteLine();
  18.            
  19.             Console.WriteLine("input your string: ");
  20.             string str = Console.ReadLine();
  21.  
  22.             int firstIndex = str.IndexOf(usrKey1.KeyChar) - 1;
  23.             int lastIndex = str.LastIndexOf(usrKey2.KeyChar);
  24.  
  25.             if (lastIndex == (-1) || firstIndex == (-1))
  26.                 Console.WriteLine("this chars is out of string");
  27.            
  28.             int count = lastIndex - firstIndex;
  29.  
  30.             Console.WriteLine(count);
  31.             Console.ReadLine();
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement