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 8408099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:32:58+00:00 2026-06-09T23:32:58+00:00

I am trying to parse some lines and check their values, For example in

  • 0

I am trying to parse some lines and check their values, For example in the string:

   " 1 ON OFF";

I have to check whether:

  • the first character is blank.
  • the second character is int.
  • the third character is blank.
  • the fourth character is 2 characters and it is ON.
  • the fifth character is blank.
  • the sixth character is 3 characters and it is OFF.

I can do this at one go using regex, but what I want is that after each check I have to display whether is correct or not like:

   System.out.println("1st character is not a blank : incorrect");
   System.out.println("1st character is blank : correct");

I thought of using Scanner class for this, but when I try to detect the first character, it is showing 1 instead of blank for the string,

   " 1 ON OFF";

   public class NewClass {    

    public void StringExample(){
        String str = " 1 ON OFF";

        Scanner sc = new Scanner(str);
        System.out.println(sc.next());
    }

    public static void main(String args[]){
        NewClass nc = new NewClass();
        nc.StringExample();
    }
}

Is there any other class in java with which this can be done easily?

  • 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-09T23:32:59+00:00Added an answer on June 9, 2026 at 11:32 pm

    The closest I can think of is splitting by word boundary:

    String tokens[] = " 1 ON OFF".split("\\b");
    

    It will give the following array:

    { " ", "1", " ", "ON", " ", "OFF" }
    

    It fits your ordering and your definition of 1st-6th “character”.

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

Sidebar

Related Questions

I am trying to parse some XML i have retrieved via e4x in an
I'm trying to parse some text using PyParser. The problem is that I have
I'm trying to parse some weather forecast lines for chance of rain and temperatures.
I am trying to use regex to parse out some lines from text read
I'm trying to get some regex to parse some values stored in a set
I'm trying to parse some HTML with XPath. Following the simplified XML example below,
I'm trying to parse some of html where there is are repeating lines of
Trying to parse an HTML document and extract some elements (any links to text
Trying to parse some XML but apparently this is too much for a lazy
I am trying to parse some results of arp -a and Michael$ arp -a

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.