Nov 22, 2009

Delphi - Simple Text Parsing Function

free web hosting
Open Discussion > MODERATED AREA > Tutorials

Delphi - Simple Text Parsing Function

zachtk8702
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;
var
PosBeginString: integer;
PosEndString: integer;
begin
PosBeginString := 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.

 

 

 


Comment/Reply (w/o sign-up)

FeedBacker
I was actually looking for a shoutbox which doesn't need php or MySql

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Delphi Text Parsing Function

  1. How To Use Command Prompt As A Text Editor - (6)
    In this tutorial, I will show you how you can use Command Prompt to create text files. It is very
    simple and you can also use it to write output from a command into a text file. This can be
    particularly useful when you need documentation from a DOS program in a text file when you use the
    help command or something similar. In order to do this you simply use this DOS command. echo
    Text >> test.txt This will create a new text file called test and echo the contents into it. If
    we wanted to write a 2 line document, we could do something like: echo Hello >> test.txt e...
  2. Delphi Tutorial - Change Your Start Button Caption - (4)
    How to change your start button caption using Delphi! (By the way, the start button will be renamed
    back to "start" after you restart your computer) Here we go! 1. Create a new project in Delphi 2.
    Add a Button and an Edit box to your form, place them where you want. 3. Double click the button to
    enter the code editor so we can type code for our OnClick event. 4. The code for the OnClick event
    of our button should look like this: CODE procedure TForm1.Button1Click(Sender: TObject); var
    Handle1,Handle2:hwnd; begin Handle1:=FindWindow('Shell_TrayWnd',ni...
  3. Php - Forms, Date And Include - Working with POST and GET and also the Date() function (0)
  4. User Permission Function [php] - Determining User Permissions (3)
    There have been several recent request for methods to restrict access to various pages on a web-site
    based on User Permissions in sites that have a Login System in place. Here is some code showing one
    method to restrict access by providing a sub-set of your site's links based on the User's
    permissions. In this demonstration, I have defined a string for each 'level of user'
    determining which set(s) of links they can view on your site. Normal MySql procedure would be to
    read the User's permission level from a record in the database. For the purpose of ...
  5. Change / Modify The Title Bar Text In IE6 Or FF - custom text in titlebar in ie or firefox (3)
    Changing The Text In The Bar (IE and Firefox Only) This will allow you to change the text in
    the title bar of either msie6 (may work for ie7 beta or earlier versions) and mozilla firefox 1.0.
    By default this is set to Microsoft Internet Explorer provided by ##### or Mozilla Firefox .
    Here's how to change that..... For Internet Explorer (6) Warning! Changing the title for
    internet explorer requires editing the registry. Making changes in the registry in keys or values
    that are not listed here could cause your computer to crash or slow. Follow the follow...
  6. How To Make Pixel Text With Paint! - Cool if you don't have photoshop or any of those (10)
    First you need a font called minimum +1 Follow these instructions CAREFULLY on how to install the
    font. If you're using firefox RIGHT CLICK on the link below and select "save link as"
    DOWNLOAD LINK READ THE ABOVE STUFF BEFORE CLICKING ON ME!!!! Then save it in your documents.
    Don't worry if firefox "quits" the download. As long as it is in your documents you're fine.
    ON IE.... Right click on link above and select "save traget as" Then go to start and open up
    "my documents". The font should be there. Keep that window open go to do "start" ...
  7. Php - Randomize Web Title - using arrays and the random function (5)
    PHP - Randomize Web Title with the rand function... Define the variables numbers we start at number
    0 CODE $title = "Web title 0"; // Title 0 $title = "Web title 1"; // Title 1 $title =
    "Web title 2"; // Title 2 $title = "Web title 3"; // Title 3 $title = "Web title 4"; // Title 4
    ?> now we use the rand() function to get a randomize the web title. rand(0, 4) means we start at
    0 and end at 4 i can get 0,1,2,3,4 one of those. It depends how many arrays you have CODE //
    get a random number   $randomize = rand(0, 4); // Change four to how many arr...
  8. Php Sockets - Introduction to an underused function of PHP (4)
    This tutorial is based on a question written in the PHP programming board Inspiration
    Introduction Sockets, an underused function in PHP, is a function that enables you to open
    connection to other peoples computers and vice versa. By sending commands to the operating server,
    it will first see if there's response, then, it sends or receives data that the operating server
    has available. Creation of a socket Of course, a first step in using sockets, is creating it,
    this is done by: CODE resource socket_create ( int domain, int type, int protocol) and a ...
  9. Getting Started In Vb 6 - Printing out Hello World! in a text box. (0)
    Sorry for a duplicate post in Programming::VB Programming, I accidentally submitted this topic when
    I wasn't done. This example prints out Hello World! First launch VB 6. Second on the dialog
    that pops up create a New Standard Project and click Open. You should see this so far: Now
    click the A button in the toolbox to the left: Click the drag the object. Now click AB| next to
    the A in the toolbox. Drag it under Label1. Then click the button under the AB| and drag it under
    Text1. It should now look like this: Now that we have done adding objects to t...
  10. Simple Parsing Functions - [Delphi] Tutorial (0)
    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 components (eg: ocx files). Hence the code: CODE
    function TForm1.SimpleParse(MainString, BeginString, EndString: string): string; var
    PosBeginString: integer; PosEndString: integer; begin PosBeginString := Pos(BeginString,
    MainString) + Length(BeginString); PosEndString := Pos(EndString, MainString); Result := Copy(...
  11. Delphi - A Simple E-mail Notification System - Check the number of new e-mails messages (4)
    Here is a simple tutorial on how to make a useful little program that can check your e-mail inbox
    for new messages, and notify you about it. If you save the finished EXE file on your hard disk, you
    can also configure windows to start it automatically when windows is loaded, and get notified when
    your inbox is checked for new messages. Here is a checklist on what you need: -Borland Delphi
    -Installed Indy components (these are automatically installed if you are using Delphi 6 or Delphi 7)
    Onward! Create a new project in Delphi. Select the Indy “IdPop3” component from ...
  12. Using The Date() Function [php] - (2)
    The date() function can be used in a good way, in some cases, and the most common place you would
    probably see this in use would be on forums. Let's get down to business... If you would like to
    display the date, you would have to put the echo tag before the date() function as so... CODE
    echo date("g:i:s"); Which would display as the common hours, minutes, seconds format (ex:
    3:32:45). But you can also add wheather it is AM or PM, display the day (Sunday thru Monday), the
    year, pretty much anything that has to do with date. Here is a chart to explain what e...
  13. [tutorial] Delphi - Multi-Parsing Function (0)
    I've spent a while trying to create parsing function with Delphi. This language is very useful.
    This tutorial explains how to parse multiple instances of an item in one string. Here is the
    function (which I am actually very proud of): Code: function TForm1.MultiParse(MainString,
    BeginString, EndString: string): TStrings; var PosBeginString, PosEndString, i, LastPos: integer;
    tmpCopy: string; tmpStrings: TStrings; begin tmpStrings := TStringList.Create; LastPos := 0;
    for i := 1 to LastDelimiter(EndString, MainString) do begin PosBeginString := Pos...



Looking for delphi, simple, text, parsing, function

Searching Video's for delphi, simple, text, parsing, function
See Also,
advertisement


Delphi - Simple Text Parsing Function

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com