• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

Scanning a string for a delimitor character

I'd like to scan a string for a character, here's an example, I'd like to scan boot.ini(from WinNT) for the char ", so that I can extract the OS label.  Anyone have any ideas?

Flinn Mueller
0
evolvelabs
Asked:
evolvelabs
  • 3
1 Solution
 
intheCommented:
Hi
this source below scans the text from a memo for the | delimiter ( change to whatever your delimiter is) and splits the text into 3 edits (i know there is 4 | in my text).
if you want i can send the demo that goes with the code below i did a while back for a test so you can visulise it better.
Regards Barry

unit gettext;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,shellapi;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Memo1: TMemo;
    Edit3: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
sl   : tstringlist;
i,j  :integer;
s,ss :string;      //ss is holding substring
begin
sl := TStringList.Create;
sl.Add(memo1.lines[0]);
 For I := 0 to SL.Count - 1 do
          begin
            S := sl[i];
            for J := 0 to 3 do
            begin
              If pos('|',s) > 0 then
              begin
                SS := Trim(copy(S,1,pos('|',s)-1));
                try
                  Case J of
                    1 : edit1.text := SS;
                    2 : edit2.text := SS;
                    3 : edit3.text := SS;
                   end;
                except
                  raise;
                  end;
              end;
             Delete(S,1,pos('|',s));
            end;
     end;
end;

end.
0
 
intheCommented:
my text in the memo looked like:

| this is a demo of | getting the text from between a delimiter | does it help you? |
0
 
evolvelabsAuthor Commented:
This is exactly what I needed, I was checking out strpos, but wasn't quite sure how to use it.
0
 
intheCommented:
glad to hear ;-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now