Jump to content
xisto Community
Sign in to follow this  
zachtk8702

Delphi Simple Text Parsing Function

Recommended Posts

Because parsing is such an integral part of string manipulation, I took the time to make a quick and simple parse function.For you VBers, Delphi is a derivative of Pascal...it's powerful, simple, and (best of all) doesn't need external component (eg: ocx files).Hence the code:Code:function TForm1.SimpleParse(MainString, BeginString, EndString: string): string;varPosBeginString: integer;PosEndString: integer;beginPosBeginString := Pos(BeginString, MainString) + Length(BeginString);PosEndString := Pos(EndString, MainString);Result := Copy(MainString, PosBeginString, PosEndString - PosBeginString);end;For example, the code:Code:ShowMessage(SimpleParse('The quick brown fox jumped over the lazy dog.', 'brown', 'jumped'));...will return the string: ' fox 'Notes:1) The instance variables PosBegin/EndString aren't needed if you replace their assigned values in the actual Copy function.2) You don't necessarily need the function to parse. You can take those three lines (or single line) of code and put it in a procedure.That is all. I may make a parsing function that parses multiple items in the future.Enjoy.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.