Hi

You're complicating.

String stripped = "";

for (int i = 0; i < sss1.lenght(); i++)
if (sss1.charAt(i) >= '0' && sss1.charAt(i) <= '9')
 stripped += sss1.charAt(i);


int start = sss1.indexOf(sss0);
int stop = start + sss0.lenght();



Hope it helps.
BTW, this group is for Android related questions, not Java questions.
On Thu, Dec 15, 2011 at 11:32, Abhishek Kumar Gupta <akgaec2...@gmail.com>wrote:

> I am having a string(number) with special characters. I want to search for
> a sub-string(comprising of digits only) & also I want to detect the
> starting index & ending index of matching sub-string in the string. For
> example: main string: *(+91)-1-231-212 12-31*
> Sub-string to search: *1212*
>
> Currently I am using the following code to do this but in place of *1212*,it
> searched for *12312*. For other cases, it works fine.
>
>    String sss0 = "1212";
>
>    String  sss1 =  "(+91)-1-231-212 12-31";
>
>     sss0 = sss0.replaceAll("[^\\d]","");
>
>     System.out.println("*************************"+sss0);
>
>     String ptn = "" + sss0.charAt(0);
>
>     for(int jj=0; jj<sss0.length()-1; jj++){
>
>         ptn += "[^" + sss0.charAt(jj) + sss0.charAt(jj+1) + "]*?" + 
> sss0.charAt(jj+1);
>
>     }
>
>          System.out.println("ptn: " + ptn);
>
>     Pattern p300 = Pattern.compile(ptn);
>
>     Matcher m300 = p300.matcher(sss1);
>
>     if(m300.find()){
>
>         System.out.println("start, stop: " + m300.start() + "," + 
> (m300.end()-1 ));
>
>         System.out.println("substring: " + sss1.substring(m300.start(), 
> m300.end()));
>
>     }
>
> *Actually I have to ignore special characters in the main string during
> searching for the sub-string*.Please help me. Thanks in advance.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to