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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:01:15+00:00 2026-05-26T04:01:15+00:00

I am trying to figure out how to take a comma-separated string as input

  • 0

I am trying to figure out how to take a comma-separated string as input and detect if there are any strings inside it that do not match the following set

{FF,SF,FB,SB,Pause}

So as I parse the string (which can be any combination of the above) if it detects “FfdsG” for example it should throw an error. I assume that I can use some sort of regex to accomplish this or a series of ifs.

EDIT….

Is my implementation bad? I am converting the string to all lower and then comparing. No matter what I send in as input (FB or FB,FF or whatever) it seems its flagging everything is bad…

    `public static String check(String modes) {
     String s = modes;
     String lower = s.toLowerCase();

       HashSet<String> legalVals = new HashSet<String>();

        legalVals.add("ff");
        legalVals.add("sf");
        legalVals.add("fb");
        legalVals.add("sb");
        legalVals.add("pause");

        String valToCheck = lower;

        if (legalVals.contains(valToCheck)) { //False
            String str = modes;
        } else {
            return "Bad value: " + modes;
        }

       return modes;
      }

To be clear, the input string can be any combination of the 5 valid values i listed. it could be 1 of them or all 5. I am just trying to detect if at any time a value is detected that is not on of the listed 5. I hope that makes sense.


Ended up going with the below.

      String[] words = {"ff", "sf", "fb", "sb", "pause"};
       List<String> validList = Arrays.asList(words); 
       String checkInput = lower;

       for (String value : checkInput.split( "," ))
       {    
        if( !validList.contains( value ) )
        {
            throw new Exception("Invalid mode specified: " + modes);
        }
       }
  • 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-26T04:01:15+00:00Added an answer on May 26, 2026 at 4:01 am

    I’m no regex wiz, but if you look at each value individually, it could give you much better control on how to report errors, and lets you decide to reject the whole input or just remove the invalid entry.

    public class InputCleaner
    {
        private final static List<String> allowedEntries = Arrays.asList( new String[] { "FF", "SF", "FB", "SB", "Pause" } );
    
        public static void main( String[] args ) throws Exception
        {
            String input = "FF,SF,FB,SB,FF,Pause";
            String input2 = "FF,SF,FB,SB,FfdsG,FF,Pause";
    
            validateInput( input );
            validateInput( input2 );
        }
    
        private static void validateInput( String input ) throws Exception
        {
            for (String value : input.split( "," ))
            {    
                if( !allowedEntries.contains( value ) )
                {
                    throw new Exception( "Found a bad input value! " + value );
                }
            }
    
            System.out.println( "Input string clean:" + input );
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to figure out if there is a way to take the
I'm trying to figure out how to take values from one of these input
Trying to figure out how to write a jquery formula that will sum all
I'm trying to figure out a way to take a date in a table
I'm trying to figure out the best approach to take in my current situation.
I'm trying to figure out the best practice to setup hierarchy data that i
So I'm trying to figure out how to take entries from the user in
I am trying to figure out what to take into consideration before porting my
I'm trying to figure out how to run a query that would go something
I'm trying to figure out how to solve some challenges that my team 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.