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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:57:13+00:00 2026-06-04T04:57:13+00:00

I want to check if a single char is in a C string. The

  • 0

I want to check if a single char is in a C string. The character is the '|'
used for pipelines in Linux (Actually, I also want to check for '<', '>', '>>', '&').

In Java I can do this:

String.indexOf()

But how can I do this in C, without looping through the whole string (a char* string)?

  • 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-04T04:57:15+00:00Added an answer on June 4, 2026 at 4:57 am

    If you need to search for a character you can use the strchr function, like this:

    char* pPosition = strchr(pText, '|');
    

    pPosition will be NULL if the given character has not been found. For example:

    puts(strchr("field1|field2", '|'));
    

    Will output: “|field2”. Note that strchr will perform a forward search, to search backward you can use the strrchr. Now imagine (just to provide an example) that you have a string like this: “variable:value|condition”. You can extract the value field with:

    char* pValue = strrchr(strchr(pExpression, '|'), ':') + 1;
    

    If what you want is the index of the character inside the string take a look to this post here on SO. You may need something like IndexOfAny() too, here another post on SO that uses strnspn for this.

    Instead if you’re looking for a string you can use the strstr function, like this:

    char* pPosition = strstr(pText, "text to find");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to end up with a single VS project/solution that I can check
I know I'm over thinking this, but I want to check a single value/field
I want to check if a single character matches a set of possible other
I want to check whether a string is a file name (name DOT ext)
I want to check the type of an Object. How can I do that?
I want to check which users accept cookies so I can get a rough
I just want to check the permissions of a single file w/o having to
In SQL: I want to check. From single table, if(field1 = 1 and DATE_SUB(CURDATE(),INTERVAL
I know that you can merge two branches together, but what about single check-ins?
I don't want check if an item with a value exists in the arraylist,

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.