Click here to Skip to main content
15,886,864 members
Please Sign up or sign in to vote.
2.80/5 (3 votes)
See more: , +
Hi,

I want to pickup character after a defined character.

Example :
if
Url = Menu[0][0]=new mI("Home","http://aps.abcd.com/details/0,8590,CLI1_DIV152_ETI3140,00.html")

i want Result = 0,0

if it is
Menu[0][1]=new mI("Home","http://aps.abcd.com/details/0,8590,CLI1_DIV152_ETI3140,00.html")
Result = 0, 1




Please help me, Thanks in advance.
Posted
Comments
george4986 11-Mar-14 3:33am    
post ur code here
OriginalGriff 11-Mar-14 4:36am    
Sorry?
That makes no sense to me - I fail to see what "defined character" you are talking about - the two string (indeed the two objects your create) appear identical.
The only difference is where you put them in your array of "mI" objects.
Please, try to explain in more detail exactly what your problem is, remembering that we can;t see your screen!
Use the "Improve question" widget to edit your question and provide better information.
omprakash katre 11-Mar-14 4:38am    
Url is my string and i want to get defined result only. I am using .net for it.


static void Main(string[] args)
{
string s = "Menu[0][0]";

for (int i = 0; i < 3; i++)
{
if(s.Contains("]"))
{
string result = s.Substring(0, s.IndexOf("]"));

Console.WriteLine(result[result.Length - 1]);

}
}
Console.ReadKey();
}
OriginalGriff 11-Mar-14 5:21am    
That still makes no sense - possibly even less than before.
All your loop will do is print the same thing three times...
and Url is not a string...it's an instance of your mI class.

I'm not trying to be awkward here, I genuinely don't understand what you are trying to do!

1 solution

It looks like your data is strings with lines like:
Url = Menu[0][0]=new mI("Home","http://aps.abcd.com/details/0,8590,CLI1_DIV152_ETI3140,00.html")
and
Menu[0][1]=new mI("Home","http://aps.abcd.com/details/0,8590,CLI1_DIV152_ETI3140,00.html")

and you want to extract the two index values used for Menu.
"0,0" and "0,1" respectively.
Going with that assumption:
C#
List<string> data = new List<string>()
  {
    "Url = Menu[0][0]=new mI(\"Home\",\"http://aps.abcd.com/details/0,8590,CLI1_DIV152_ETI3140,00.html\")",
    "Menu[0][1]=new mI(\"Home\",\"http://aps.abcd.com/details/0,8590,CLI1_DIV152_ETI3140,00.html\")"
  };

Regex indexFinder = new Regex(@"Menu\[(\d+)\]\s*\[(\d+)\]");

foreach (string datum in data)
{
  Match indexMatch = indexFinder.Match(datum);
  if (indexMatch.Success)
  {
    Console.Writeline(index.Match.Groups[1].Value + "," + index.Match.Groups[2].Value);
  }
}


Yes, I could have used a format string with the Console.Writeline() but the original request might need the two values as a single string for some other purpose. ;)
 
Share this answer
 
v3
Comments
omprakash katre 18-Mar-14 3:57am    
Thanks for reply,Now its working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900