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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:01:05+00:00 2026-06-06T17:01:05+00:00

I have a string line like the following : A:B:C:D:E:F:G:H:I:J:K:L:M It means delimiter (

  • 0

I have a string line like the following :

A:B:C:D:E:F:G:H:I:J:K:L:M

It means delimiter ( : ) count is 12 . This line is valid.

Now suppose you have a following line :

A:B:C:D:E:F:G:H:::::

This line is also valid because it contains 12 delimiter . where 8 values are present and 4 values are blank.

Now the following line should be invalid :

A:B:C:D:E:F: — Invalid – because it contains only 6 values but expected are 12.

how to do this .. ? I tried the following code , but not getting the desired output :

String strLine = "A:B:C:D:E:F:G:H:::::" ;
int delimiterCount = 12 ; 

String[] ValuesArray = strLine.split(":");
 if(ValuesArray.length != delimiterCounter){
 System.out.println(Invalid);
 }else {
 System.out.println("ValidLine");
 }

I am getting the output as Invalid where as it sould be Valid.

  • 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-06T17:01:07+00:00Added an answer on June 6, 2026 at 5:01 pm

    If you want to use split, and it’s not a bad approach really (although it might be for this particular situation), you need to pass -1 as the second argument to split otherwise it removes empty strings.

    See http://ideone.com/gaUw5.

    It is good to know this about split. Some languages require the -1 and some do not.

    The code

    class Main {
        public static void main(String[] args) {
            String line = "A:B:C:D:E:F:G:H:::::" ;
            int delimiterCount = 12 ; 
    
            String[] values = line.split(":", -1);
            if (values.length != delimiterCount + 1) {
                System.out.println("Invalid Line");
            } else {
                System.out.println("Valid Line");
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a string in a variable in MATLAB like the following: this
I have a multiple line string like following: END IF; EXECUTE IMMEDIATE ' CREATE
I have a line like the following in my code: string buffer = string.Format(CultureInfo.InvariantCulture,
I have got a cookie string from HTTP response header like the following line:
I have a string like this This:string:must~:be:split:when:previous:char:is:not~:this I need to split the line with
I have this line in the declarations section: Private filePath As String And something
Say I have the following line in a method: String encodedString = URLEncoder.encode(foo, utf-8);
I have the following line of code. <%= Html.Encode(string.Join(, , item.company1.companies.Select(x => x.company_name).ToArray())) %>
I have a line like the following in a method that I want to
I have the following data that looks like this for example: 34 foo 34

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.