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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:50:36+00:00 2026-05-22T20:50:36+00:00

I am trying to manipulate a string and pull only certain data from it.

  • 0

I am trying to manipulate a string and pull only certain data from it. I need to do this on a record pulled from a database that gives me the full name of a person. I need to pull only the last name from the string and store it as a variable. Is there a way that I can do this?

Example: SQL query pulls the full field “Mary Ellen Jones” I need to extract only the Jones from the string so I can store it in a variable for further processing.

I thought maybe AnsiRightStr would work but the problem is needing to give it a set integer to pull from the right. Maybe a way to count the characters after the final space allowing me to use AnsiRightStr(string,int) for this? Any help at all is appreciated.

Additional thought: Would replacing the spaces with a delimiter say :: and then parsing that data into a Stringlist followed by allowing me to pull the last index of the string list be possible?

Several valid options have been presented so far. None of them address the situation if say the name is Something like “John St. James, Jr.” Is this impossible?

  • 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-22T20:50:36+00:00Added an answer on May 22, 2026 at 8:50 pm

    What if the last name is say “St. James” any way to account for that?

    Here’s my approach.

    1. Make a list of lastname-markers
    2. Search that list in order of preference
    3. As soon as a match is found, mark that as the start of last name
    4. Return substring starting from that pos.
    var
      LastNameMarkers: TStringList = nil;
      SuffixFix: TStringList = nil;
    
    procedure InitLists;
    begin
      LastNameMarkers:= TStringList.Create;
      //LastNameMarkers.LoadFromFile('c:\markers.txt');
      LastNameMarkers.Add(' St.');
      LastnameMarkers.Add(' Mc');
      LastNameMarkers.Add(' '); //Marker of last resort.
      SuffixFix:= TStringList.Create;
      SuffixFix.Add(' Jr.');
      SuffixFix.Add(' Sr.');
    end;
    
    function GetLastName(FullName: string): string;
    var
      i: integer;
      start: integer;
      found: boolean;
      ReplaceWith: string;
    begin
      if LastNameMarkers = nil then InitLists;
    
      //Fix suffixes
      i:= 0;
      found:= false;
      while (i < SuffixFix.Count) and not found do begin
        start:= pos(lower(LastNameMarkers[i]),lower(Fullname));
        found:= Start > 0;
        Inc(i);
      end; {while}
      if Found then begin 
        Dec(i);
        ReplaceWith:= StringReplace(Suffix[i], ' ', '_',[]);
        FullName:= StringReplace(FullName, SuffixFix[i], ReplaceWith,[]);
      end; {if}
    
      //Look for lastnames 
      i:= 0;
      found:= false;
      while (i < LastNameMarkers.Count) and not found do begin
        start:= pos(LastNameMarkers[i],Fullname);
        found:= Start > 0;
        Inc(i);
      end; {while}
    
      if found then Result:= RightStr(FullName, Length(FullName)- Start + 2)
      else Result:= '';
    
      StringReplace(Result, '_', ' ',[]);
    end;
    

    I haven’t dealt with upper and lowercase properly, but I hope you get the idea.

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

Sidebar

Related Questions

I am trying to manipulate a conditional string outputted from SAS into the right
I have a simple string that I'm trying to manipulate: Your order will be
i need to enter a string to my database, this string may contain this
I am trying to manipulate a string using Jython, I have included below an
It strikes me that Properties in C# should be use when trying to manipulate
I'm trying to create some classes that allow me to retrieve and manipulate a
I'm trying to write emacs tools that require sending data to an external process,
Revised: I have a list items on the page that I'm creating from database
I am trying to extract data from a xml file, get rid of the
I have a string that I want to extract text between comment tags, manipulate

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.