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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:52:09+00:00 2026-05-22T00:52:09+00:00

I have a long string that I want to strip off the end. I

  • 0

I have a long string that I want to strip off the end. I want to get rid of everything after the character “<” (inclusively). Here is the code that works:

char *end;
end = strchr(mystring, '<');
mystring[strlen(mystring) - strlen(end)] = '\0';

So if mystring was

"asdfjk234klsjadflnwer023jokmnasdf</tag>alskjdflk23<tag2>akjsldfjsdf</tag2>blabla"

this code would return

"asdfjk234klsjadflnwer023jokmnasdf"

I’m wondering if this can be done in a easier way? I know I can increment a counter over each character in mystring till I find “<” and then used that int as the index, but that seems equally troublesome. All the other built-in string libraries don’t seem useful but I’m sure I’m just looking at this in the wrong way. I haven’t used C for years.

Any help is appreciated!

  • 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-22T00:52:10+00:00Added an answer on May 22, 2026 at 12:52 am

    Sure. This is the idiomatic way to do it:

    char *end;
    end = strchr(mystring, '<');
    if (end)
        *end = '\0';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a long string, want to break that string in new line after
I've got the problem, that I want to cut-off a long string after the
I have a simple question. I have a long std::string that I want to
I have a long string that I want to encode to ascii. I'm doing:
I have some rather long string containing just about anything that I want to
I have a very long string that I want to split into 2 pieces.
I have a long string that will be displayed on my page. I want
I have a long string that contains a styled tag that I want to
I have a Long string from that I want to store the keyword in
I have an extremely long string that I want to parse for a numeric

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.