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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:56:16+00:00 2026-05-18T23:56:16+00:00

My string is like this: string input = STRIP, HR 3/16 X 1 1/2

  • 0

My string is like this:

string input = "STRIP, HR 3/16 X 1 1/2 X 1 5/8 + API";

Here actually I want to extract the last word, ‘API’, and return.

What would be the C# code to do the above extraction?

  • 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-18T23:56:17+00:00Added an answer on May 18, 2026 at 11:56 pm

    Well, the naive implementation to that would be to simply split on each space and take the last element.

    Splitting is done using an instance method on the String object, and the last of the elements can either be retrieved using array indexing, or using the Last LINQ operator.

    End result:

    string lastWord = input.Split(' ').Last();
    

    If you don’t have LINQ, I would do it in two operations:

    string[] parts = input.Split(' ');
    string lastWord = parts[parts.Length - 1];
    

    While this would work for this string, it might not work for a slightly different string, so either you’ll have to figure out how to change the code accordingly, or post all the rules.

    string input = ".... ,API";
    

    Here, the comma would be part of the “word”.

    Also, if the first method of obtaining the word is correct, that is, everything after the last space, and your string adheres to the following rules:

    • Will always contain at least one space
    • Does not end with one or more spaces (in case of this you can trim it)

    Then you can use this code that will allocate fewer objects on the heap for GC to worry about later:

    string lastWord = input.Substring(input.LastIndexOf(' ') + 1);
    

    However, if you need to consider commas, semicolons, and whatnot, the first method using splitting is the best; there are fewer things to keep track of.

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

Sidebar

Related Questions

I have string like this /c SomeText\MoreText Some Text\More Text\Lol SomeText I want to
How to generate an n-gram of a string like: String Input=This is my car.
I'm stuck with regular expression and Java. My input string that looks like this:
Given a string like this: a,string, with,various,values, and some,quoted What is a good algorithm
Given a UTC time string like this: 2005-11-01T00:00:00-04:00 What is the best way to
I am having an string like this string str = dfdsfdsf8fdfdfd9dfdfd4 I need to
I have a string like this that I need to parse into a 2D
I have a string like this: string s = This is my string; I
I'm used to passing around string like this in my C++ applications: void foo(const
Using PHP, what's the fastest way to convert a string like this: 123 to

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.