0

I did:

public static String textforspeech = "";

Then:

                        String a = null;
                        try
                        {
                            a = new String(checkServer, "UTF-8");
                            textforspeech = a;
                            if (textforspeech.equals("upload completed"))
                                MainActivity.this.initTTS();
                            if (textforspeech.equals("uploading"))
                            {
                                servercheckCounter += 1;
                                if (servercheckCounter == 1)
                                {
                                    MainActivity.this.initTTS();
                                }
                            }
                        } catch (UnsupportedEncodingException e)
                        {
                            e.printStackTrace();
                        }

What i'm doing is:

if (textforspeech.equals("uploading"))

But now i changed it and textforspeech will contain:

uploading 345445

Then in a next update it will be:

uploading 345446

Then:

uploading 345447

Somehow i want to check if textforspeech contains "uploading" and if it does parse the number from the string. I know that if it does contains "uploading" it's also contain the number that will be update each time.

How do i check if it contains "uploading" and then how do i parse the number so in the end i will have two strings variables one contain all the time the "uploading" and one will contain the number "345445" then "uploading" and "345446" not a new string each time the number is updated just to parse the "uploading" and the number to two strings.

Daniel van wolf
  • 393
  • 1
  • 5
  • 16
  • 1
    Take a look at the String class and its [`contains`](http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#contains(java.lang.CharSequence)) and [`split`](http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String)) methods ;) – eric.m Sep 08 '15 at 22:20

2 Answers2

1
if ("uploading 345446".contains("uploading")) {
String[] split = "uploading 345446".split(" ");
}
Vladislav Kievski
  • 1,637
  • 11
  • 12
0

:) http://www.tutorialspoint.com/java/lang/string_contains.htm

public class StringDemo {

   public static void main(String[] args) {

   String str1 = "tutorials point", str2 = "http://";

   CharSequence cs1 = "int";

   // string contains the specified sequence of char values
   boolean retval = str1.contains(cs1);
   System.out.println("Method returns : " + retval);

   // string does not contain the specified sequence of char value
   retval = str2.contains("_");   
   System.out.println("Methods returns: " + retval);
   }
}
Alexandre Beaudet
  • 2,774
  • 2
  • 20
  • 29