Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9207367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:22:18+00:00 2026-06-18T00:22:18+00:00

I am using a terminal emulator library to create a terminal and then I

  • 0

I am using a terminal emulator library to create a terminal and then I use it to send the data entered over serial to a serial device. Not that I have that working I want to create some other graphical interface, maybe just a textBox, on screen which shows a briefer version of the results for the user alongside the full version in the terminal. They can just glance at this for a quicker view of results. I’m wondering how to parse it best. When I send a command a byte array is sent back to me containing data like this as an example of one set of results:

Interface           IP-Address       Status                Protocol        
vlan1               192.168.1.1      up                    up  
Fa0/1i              unassigned       administratively down down
Fa0/1o              unassigned       down                  down
Fa1/0               unassigned       down                  down
Fa1/1               unassigned       down                  down
Fa1/2               unassigned       down                  down
Fa1/3               unassigned       down                  down
Fa1/4               unassigned       down                  down
Fa1/5               unassigned       down                  down
Fa1/6               unassigned       down                  down
Fa1/7               unassigned       down                  down
Fa1/8               unassigned       up                    up  
Fa1/9               unassigned       down                  down
Fa1/10              unassigned       up                    up  
Fa1/11              unassigned       down                  down
Gi0                 unassigned       up                    up  
switch# 

How would I parse this? I would like something like “The interface vlan1 is up with an IP of 192.1.1.168” or “the interface Fa1/8 is up with an unassigned IP address.” to appear for the user, just listing the most pertinent data. Would I just say something like:

    if (dataReceived.charAt(i) == 'v'
    && dataReceived.charAt(i + 1) == 'l'
    && dataReceived.charAt(i + 2) == 'a'
    && dataReceived.charAt(i + 3) == 'n')
    && dataReceived.charAt(i + 4) == '1')
    && etc //check i is in bounds, check is the next non-whitespace character a number or a u somehow and so on 
        {
         //do things here
         //print out "The interface vlan1 is up with an IP of 192.1.1.168"
        }

This way seems quite tedious, checking every byte, seeing what the next bytes are and so on. Is this the best/a correct way however?

EDIT: here is a sample I have at the moment, where I am receiving data, and where I am testing it for certain data:

public void onDataReceived(int id, byte[] data) {


            dataReceived = new String(data);


        try {
            dataReceivedByte = dataReceived.getBytes("ASCII");
        } catch (UnsupportedEncodingException e) {
            Log.d(TAG, "exception");
            e.printStackTrace();
        }
        statusBool = true;
        Log.d(TAG, "in data received " + dataReceived);
        ((MyBAIsWrapper) bis).renew(data);


        runOnUiThread(new Runnable(){

            @Override
            public void run() {


            }});
        viewHandler.post(updateView);
    }


Handler viewHandler = new Handler();
    Runnable updateView = new Runnable() {
        @Override

        public void run() {

            mEmulatorView.invalidate();

            if (statusBool == true) {
                for (int i = 1; i < dataReceived.length() - 1; i++) {

                    if (dataReceived.charAt(i) == '>') {

                        Log.d(TAG, "found >");
                        deviceStatus = 0;
                    }
                    if (dataReceived.charAt(i) == '#'
                            && dataReceived.charAt(i - 1) != ')') {

                        Log.d(TAG, "found #");
                        deviceStatus = 1;
                    }
                    if ((i + 1) <= (dataReceived.length())
                            && dataReceived.charAt(i) == ')'
                            && dataReceived.charAt(i + 1) == '#') {

                        Log.d(TAG, "found config )#");
                        deviceStatus = 2;
                    }

                }
                statusBool = false;
                viewHandler.postDelayed(updateView, 1000);

            }
        }
    };
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:22:20+00:00Added an answer on June 18, 2026 at 12:22 am

    As you are using charAt(), I suppose that dataReceived is a String. If not, it might be convenient to convert the data into a string, as you can then make use of the convenient String methods. You can covnert a byte array to a string using the String(byte[]) constructor.

    So, you could also use the contains() method to check if the string contains a particular substring:

    if(dataReceived.contains("vlan1")) {
      // do things here
    }
    

    Or if you are interested in the location of the substring you can use indexOf().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a terminal emulator library to create a terminal and then I
I am using a terminal emulator library to create a terminal and then I
I am trying to connect to a terminal emulator using a library in android,
I am connecting to a terminal emulator using a library in android, this connects
I am connecting to a terminal emulator using a library in android, this connects
Updated question: I am trying to connect to a terminal emulator using a library
I am connecting to a terminal emulator using a library in android, this connects
I am connecting to a terminal emulator using a library in android, this connects
I am connecting to a terminal emulator using a library in android, this connects
I am writing a terminal emulator in ruby using the PTY library. /dev/tty0 is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.