Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to split string? 1

Status
Not open for further replies.

KenChristensen

Programmer
Jun 23, 2002
74
0
0
DK
Hi,

Iam working on a html editor and I am making a funktion for users to edit html tags.
(ex: user marks a line in editor and it opens a form. Then the form gets the information from the lins).

But how do I split the string so i get the text between the 2 first "s and the next 2? Ken Christensen
Kenman@Kenman.tk
 
I used this bit of code to separate path and name of a file.
Code:
speech_marks := 0;
for counter := 1 to Length(MyString) do
  if(IsDelimiter('"', MyString, counter)) then
  begin   
    speech_marks := speech_marks + 1;
    case speech_marks of
      1: first_pos := counter;
      2: second_pos := counter;
      3: third_pos := counter;
      4: fourth_pos := counter;
    end;
  end;
end;

FirstWord := Copy(MyString, first_pos, second_pos);
SecondWord := Copy(MyString, third_pos, fourth_pos);

Not sure this is the best way to do it, but it should work ok!
 
Ok...I used this bit of code to separate path and name of a file:

Code:
  db_length := Length(db_path_and_name);
  for counter := 1 to db_length do
    if(IsDelimiter('\', db_path_and_name, counter)) then
      final_delimiter := counter; 
      {indicates position of backslash in string}
  
  db_path := Copy(db_path_and_name, 1, final_delimiter);
  db_name := Copy(db_path_and_name, final_delimiter + 1, db_length);

Basically when the for loop is terminated
Code:
 final_delimiter
will store the position of the last backslash in the string.
 
For dir paths and filenames you can sue ExtractFileDir and ExtractFileName.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top