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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:22:34+00:00 2026-06-15T18:22:34+00:00

Platform : Lazarus 1.1, FreePascal 2.7.1, Win 7 32-bit. I have a string value

  • 0

Platform : Lazarus 1.1, FreePascal 2.7.1, Win 7 32-bit.

I have a string value as follows:

FileName[12345][45678][6789].jpg

By default (assume this is default behaviour 0), my program currently pulls out the last set of numbers from the last pair of square brackets to the farthest right of the filename, i.e. 6789. It does so using this code:

if chkbxOverrideUniqueID.Checked then
   IDOverrideValue := StrToInt(edtToggleValue.Text);   
// User is happy to find the right most unique ID
if not chkbxOverrideUniqueID.Checked then      
  LastSquareBracket := RPos(']', strFileName);
  PreceedingSquareBracket := RPosEx('[', strFileName, LastSquareBracket) + 1;
  strFileID := AnsiMidStr(strFileName, PreceedingSquareBracket, LastSquareBracket - PreceedingSquareBracket)
else // User doesn't want to find the rightmost ID. 
  // and now I am stuck! 

However, I have now added an option for the user to specify a non-default behaviour. e.g if they enter ‘1’, that means “look for the first ID in from the farthest right ID”. e.g. [45678], because [6789] is default behaviour 0, remember. If they enter 2, I want it to find [12345].

My question : How do I adapt the above code to achieve this, please?

  • 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-15T18:22:36+00:00Added an answer on June 15, 2026 at 6:22 pm

    The following code will return just the numeric value between brackets:

    uses
      StrUtils;
    
    function GetNumber(const Text: string; Index: Integer): string;
    var
      I: Integer;
      OpenPos: Integer;
      ClosePos: Integer;
    begin
      Result := '';
      ClosePos := Length(Text) + 1;
      for I := 0 to Index do
      begin
        ClosePos := RPosEx(']', Text, ClosePos - 1);
        if ClosePos = 0 then
          Exit;
      end;
      OpenPos := RPosEx('[', Text, ClosePos - 1);
      if OpenPos <> 0 then
        Result := Copy(Text, OpenPos + 1, ClosePos - OpenPos - 1);
    end;
    

    If you’d like that value including those brackets, replace the last line with this:

    Result := Copy(Text, OpenPos, ClosePos - OpenPos + 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

platform- win. Well i'm trying to get a value of a key named SunJavaUpdateSched
Platform - iOS. Language - Object c, OpenGL. I have to put 2 UIViews
Platform: Windows 7, 64 bit (x64), Visual Studio 2008 I chose Python & Swig
Platform: ASP.NET 3.5, ASP.NET Ajax intermixed I'm very green to jQuery, so have been
Platform: C# 2.0 WinForms I have a factory class that provides an instantiation of
Platform: C# ASP.NET 3.5 I have a ListView which builds a Rate field which
platform :sql server 2000 java 1.4 String queryStringForCustomer = {call MIGRATE_CUSTOMERS_FILE(?,?)}; String queryStringForCard =
Platform: Silverlight 4 / .NET 4 Description: I have a ComboBox , a Textbox
I have a NetBeans Platform based application using NetBeans platform 7.1.1. I have various
Platform: Flex 3 & Flex 4 Language: AS3 I have inherited a very large

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.