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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:59:59+00:00 2026-05-20T03:59:59+00:00

What is the shortest way to check if a string contains the character –

  • 0

What is the shortest way to check if a string contains the character “-” or it contains only numbers?

Edit: And how would I do it in C without std::string? Which one is better?

  • 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-20T04:00:00+00:00Added an answer on May 20, 2026 at 4:00 am

    std::string has a member function, find, which can be used to search for a character or substring. It returns std::string::npos if the search character or substring is not found.

    One straightforward way to test whether a string contains only digits is to use the find_first_not_of member function with the search list "0123456789". If it returns std::string::npos, the string contains only digits; if it returns any other value, there is some other, nondigit character in the string.

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

Sidebar

Related Questions

What would be the fastest/shortest way to create a string of repeating characters. For
What's the shortest way to do this in Python? string = xyz must return
what would be the shortest way to write this? if(strpos($haystack, $needle)!==false){ $len = strpos($haystack,
What's the shortest, one-liner way to list all methods defined with attr_accessor ? I
what's the shortest way of returning an Entity Framework object from one table based
What is the fastest, one-liner/shortest way to get an Array of strings/that/are/paths from an
What is the shortest way to convert a DataTable into a string (formatted in
Possible Duplicate: What is the best way to slurp a file into a std::string
What is the best (shortest) way to read the next non-blank (not space/newline/tab) character
I don’t know which is the shortest way to look at the error descriptions

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.