thanks serge, great communication.

right now its ok for me, because the code who does create the tags is
also from me :)
so i can be sure there is always a start and ending tag.

just for anyone who is interested here an extended version that does
allow to
search for several tags in a long string (for example, the first
appearance, the second ...)

When there is nothing found, it returns the string "!NULL!" (because
"" may also happen if
there is just nothing between an open and end tag :)
and finaly you can say it should short a long response ...
Now its finished for my purpose... so just like to share with you,
should u need something like that.


        //TakeIt ("yourtag", TheSourceString, WhatPosition, length of
return)
        public String TakeIt(String xtag, String xhtml, int xpos, int xmax)
        {
                int xstart = 0;
                String xfound = "";
                int xcounter = 0;
                // xhtml = "hallo, <d>das</d> ist ein <d>test</d von mir 
<d>an</d>
dich
                do
                {
                        xcounter++;
                        String x1tag = "<" + xtag + ">";
                        String x2tag = "</" + xtag + ">";
                        xstart = xhtml.indexOf(x1tag);
                        if (xstart != -1)
                        {
                                int x1len = x1tag.length();
                                int xend = xhtml.indexOf(x2tag);
                                if (xend != -1)
                                {
                                        int x2len = x2tag.length();

                                        if (xcounter == xpos) xfound = 
xhtml.substring(xstart + x1len,
xend);
                                        // cut till here
                                        xhtml = xhtml.substring(xend + x2len);
                                } else
                                {
                                        xfound = "!NULL!";
                                }
                        } else
                        {
                                xfound = "!NULL!";
                        }
                } while ((xfound != "!NULL!") && (xcounter < xpos));

                if (xfound.length() > xmax) xfound = 
xfound.substring(0,xmax)+"...";

                return xfound;
        }


------
Also what I am thinking about, is there a Class List with several
such
simple Commands for Android that makes Live more easy?
I really think so start a small project with a class everyone just can
include in his
own project and wih several simple functions.

Right now I am still looking for a solution with my Listview and
Gallery Update
after a Thread..

http://groups.google.com/group/android-beginners/browse_thread/thread/1bdc014cee0d317b/4f8e097e30167641?hl=en#4f8e097e30167641

You are welcome to help and share your sources ( please if possible
always with working source Code,
special Beginners like me are very happy about :)

Greets
Chris







On Mar 15, 3:55 pm, sm1 <sergemas...@gmail.com> wrote:
> Looks good guruk. It's quite fast. I timed it.
>
> fyi: The code I posted earlier can also work with input of xml tags
> with attributes, such as
>
> "Hello, this is a test <start attr1=\"value1\">12345</start> ..."
>
> which is common with tags, and it also avoids raising the nasty
> RuntimeException IndexOutOfBoundsException (by method substring) when
> a tag is not in the given string, which can happen in my apps.
> Exceptions such as these are normally not indicated by Eclipse Europa
> because, being RuntimeException children, they do not require a throws
> clause in the method signature when they are not caught by a try-catch
> in the method. These things often are what makes the difference
> between a 3-star and a 4-star rating.
>
> For handling absent tags without having to manage the exception
> downstream, I recommend the use of {if(xstart<0)return "";}
>
>       String x1tag = "<" + xtag + ">";
>       String x2tag = "</" + xtag + ">";
>       int xstart = xhtml.indexOf(x1tag);
>       if(xstart<0)return "";
>       int x1len = x1tag.length();
>       int xend = xhtml.indexOf(x2tag);
>       if(xend<0)return "";
>       return xhtml.substring(xstart + x1len, xend);
>
> Or you could use a try-catch clause in the method if you know that the
> exception will not occur frequently and you don't want to do anything
> with the exception, and you want to keep going, such as:
>
>     try{
>       String x1tag = "<" + xtag + ">";
>       String x2tag = "</" + xtag + ">";
>       int xstart = xhtml.indexOf(x1tag);
>       int x1len = x1tag.length();
>       int xend = xhtml.indexOf(x2tag);
>       return xhtml.substring(xstart + x1len, xend);
>     }catch(Throwable resume){
>       return "";
>     }
>
> regards,
> serge
>
> On Mar 14, 2:38 pm, guruk <ilovesi...@gmail.com> wrote:
>
>
>
> > Hi and thanks for all your great help
>
> > So I also like to share what I use now
>
> > public String TakeIt (String xtag, String xhtml)
> >         {
> >                 String x1tag = "<" + xtag + ">";
> >                 String x2tag = "</" + xtag + ">";
> >                 int xstart = xhtml.indexOf(x1tag);
> >                 int x1len = x1tag.length();
> >                 int xend = xhtml.indexOf(x2tag);
> >                 return xhtml.substring(xstart + x1len, xend);
> >         }
>
> > And as Usual.. one Problem is solved, the next appear.
>
> > Please if you know how to update a Gallery and also a Listview after a
> > Thread
> > answer 
> > here:http://groups.google.com/group/android-beginners/t/1bdc014cee0d317b
>
> > Great People!!
>
> > Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to