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

  • Home
  • SEARCH
  • 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 7187921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:57:12+00:00 2026-05-28T18:57:12+00:00

This may be a simple question, but I have been Googling for over an

  • 0

This may be a simple question, but I have been Googling for over an hour and haven’t found an answer yet.

I’m trying to simply use the String.split() method with a small Android application to split an input string. The input string will be something along the lines of: “Launch ip:192.168.1.101;port:5900”. I’m doing this in two iterations to ensure that all of the required parameters are there. I’m first trying to do a split on spaces and semicolons to get the individual tokens sorted out. Next, I’m trying to split on colons in order to strip off the identification tags of each piece of information.

So, for example, I would expect the first round of split to give me the following data from the above example string:
(1) Launch
(2) ip:192.168.1.101
(3) port:5900

Then the second round would give me the following:
(1) 192.168.1.101
(2) 5900

However, the following code that I wrote doesn’t give me what’s expected:

private String[] splitString(String inputString)
{
    String[] parsedString;
    String[] orderedString = new String[SOSLauncherConstants.SOCKET_INPUT_STRING_PARSE_VALUE];

    parsedString = inputString.trim().split("; ");

    Log.i("info", "The parsed data is as follows for the initially parsed string of size " + parsedString.length + ": ");
    for (int i = 0; i < parsedString.length; ++i)
    {
        Log.i("info", parsedString[i]);
    }

    for (int i = 0; i < parsedString.length; ++i )
    {
        if (parsedString[i].toLowerCase().contains(SOSLauncherConstants.PARSED_LAUNCH_COMMAND_VALUE))
        {
            orderedString[SOSLauncherConstants.PARSED_COMMAND_WORD] = parsedString[i];
        }

        if (parsedString[i].toLowerCase().contains("ip"))
        {
            orderedString[SOSLauncherConstants.PARSED_IP_VALUE] = parsedString[i].split(":")[1];
        }
        else if (parsedString[i].toLowerCase().contains("port"))
        {
            orderedString[SOSLauncherConstants.PARSED_PORT_VALUE] = parsedString[i].split(":")[1];
        }
        else if (parsedString[i].toLowerCase().contains("username"))
        {
            orderedString[SOSLauncherConstants.PARSED_USERNAME_VALUE] = parsedString[i].split(":")[1];
        }
        else if (parsedString[i].toLowerCase().contains("password"))
        {
            orderedString[SOSLauncherConstants.PARSED_PASSWORD_VALUE] = parsedString[i].split(":")[1];
        }
        else if (parsedString[i].toLowerCase().contains("color"))
        {
            orderedString[SOSLauncherConstants.PARSED_COLOR_VALUE] = parsedString[i].split(":")[1];
        }
    }

    Log.i("info", "The parsed data is as follows for the second parsed string of size " + orderedString.length + ": ");
    for (int i = 0; i < orderedString.length; ++i)
    {
        Log.i("info", orderedString[i]);
    }

    return orderedString;
}

For a result, I’m getting the following:
The parsed data is as follows for the parsed string of size 1:

launch ip:192.168.1.106;port:5900

The parsed data is as follows for the second parsed string of size 6:

launch ip:192.168.1.106;port:5900

192.168.1.106;port

And then, of course, it crashes because the for loop runs into a null string.

Side Note:
The following snippet is from the constants class that defines all of the string indexes —

public static final int SOCKET_INPUT_STRING_PARSE_VALUE = 6;
public static final int PARSED_COMMAND_WORD = 0;
public static final String PARSED_LAUNCH_COMMAND_VALUE = "launch";
public static final int PARSED_IP_VALUE = 1;
public static final int PARSED_PORT_VALUE = 2;
public static final int PARSED_USERNAME_VALUE = 3;
public static final int PARSED_PASSWORD_VALUE = 4;
public static final int PARSED_COLOR_VALUE = 5;

I looked into needing a possible escape (by inserting a \\ before the semicolon) on the semicolon delimiter, and even tried using it, but that didn’t work. The odd part is that neither the space nor the semicolon function as a delimiter, yet the colon works on the second time around. Does anybody have any ideas what would cause this?

Thanks for your time!

EDIT: I should also add that I’m receiving the string over a WiFi socket connection. I don’t think this should make a difference, but I’d like you to have all of the information that you need.

  • 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-05-28T18:57:13+00:00Added an answer on May 28, 2026 at 6:57 pm

    String.split(String) takes a regex. Use "[; ]". eg:

    "foo;bar baz".split("[; ]")
    

    will return an array containing "foo", "bar" and "baz".

    If you need groups of spaces to work as a single delimiter, you can use something like:

    "foo;bar     baz".split("(;| +)")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay this may be a simple question but I have yet to come with
This may seem like a very simple question, but I have been struggling with
may be too simple groovy question but....please help i have a list like this:
I have a question that may have been answered over 9000 times before but
This may be very simple question,But please help me. i wanted to know what
This may seem like a simple question but i am getting an error when
this may be a very simple question, but is it possible to force a
This may seem a very silly question. Consider this: I have a simple Boolean
This may be simple one, but 5 mins of Googling didn't give me the
This may be a simple fix - but I'm trying to sum together all

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.