2017-05-30 5 views
0

私はこのようなもので、ユーザの入力を読み取るためにアンドロイドに正規表現をウッシングいますが見つかりません私はarduinoにこの入力を送る)アンドロイド正規表現マッチャー

私はユーザーがラインを壊すかどうかを確認する必要があります。もしそうなら、私はarduinoにラインを送ります。行が 'd'(2番目のものと同様)で始まっている場合は、遅延を設定し、その時間はその行の次の整数になります。マッチャが

私は、コンパイルに設定したものが見つかった場合、ここで

は私のコードですが、私は検証しようとすると問題がある

final String expression = aux.getCodigo().toString(); 
        //System.out.println("mandeii " + MenuActivity.mIn.read()); 

        Pattern pattern = Pattern.compile("'(\n)'"); 
        Matcher matcher = pattern.matcher(expression); 
        System.out.println("achei "); 
        if (matcher.find()){ 
         System.out.println("found the first endLine"+ matcher); 
         if (matcher.group(0).charAt(0) == 'd') { 
          System.out.println("achei o d "+matcher.group(0).charAt(0)); 
          int v1 = matcher.group(0).charAt(1); 
          if (matcher.group(0).charAt(2) != '\n') { 
           int v2 = matcher.group(0).charAt(2); 
           int valor = Integer.parseInt(String.valueOf(v1) + String.valueOf(v2)); 
           System.out.println("valor "+valor); 
           new CountDownTimer(valor * 1000, 1000) { 
            public void onFinish() { 
             System.out.println("delayed"); 
            } 

            public void onTick(long millisUntilFinished) { 
             // millisUntilFinished The amount of time until finished. 
            } 
           }.start(); 

          } else { 
           new CountDownTimer(v1 * 1000, 1000) { 
            public void onFinish() { 
             System.out.println("delayed"); 
            } 

            public void onTick(long millisUntilFinished) { 
             // millisUntilFinished The amount of time until finished. 
            } 
           }.start(); 

          } 

         } 
         else MenuActivity.mOut.write(matcher.group(0).getBytes()); 

誰かが知っている場合、それは、私に TKSを大いに役立つだろう

+0

を\あなたは'のstring.Split(System.lineSeparatorを()を使用することができますN ' ) ' –

答えて

0

したがって、\ nをチャンク区切り記号として使用して、行をチャンク(分割)に分割するだけで済みます。右?そして、なぜそれが非常に複雑にするために、そこにあるので、素敵な方法で分割:あなたは、キャリッジリターンで行を分割したい場合は、 `

// This must run in a NON-UI thread! 
    //===================================== 
    try { 
    for (String chunk: expression.split("\n")) { 
     if (chunk.charAt(0) == 'd') { 
      int valor; 
      if (chunk.length() > 1 && 
       (valor = Integer.parseInt(chunk.substring(1)))> 0) { 
        System.out.println("Delay " + valor + " millisec"); 
        Thread.sleep(valor); 
      } 
     } else 
      MenuActivity.mOut.write(chunk.getBytes()); 

     } // End of for loop 
    } catch(InterruptedException ex) { 
     System.out.println("Cancelled"); 
    } 

    } 
+0

これは完全に正しいシアン化物です。私は現在のスレッドを使用することができたことを忘れていた... tks :) – 4ury0n