GetToken

I don't know if this will help you, but the following (simple) functions helped me handling substrings. Perhaps you can use them to seperate the text for each field (for i := 1 to NumToken do ...) and store it seperatly in the database-fields.


function GetToken(aString, SepChar: String; TokenNum: Byte):String;

{

parameters: aString : the complete string

  SepChar : a single character used as separator

  between the substrings

  TokenNum: the number of the substring you want

result : the substring or an empty string if the are less then

  'TokenNum' substrings

}

var

  Token : String;

  StrLen : Byte;

  TNum : Byte;

  TEnd : Byte;

 

begin

  StrLen := Length(aString);

  TNum := 1;

  TEnd := StrLen;

  while ((TNum <= TokenNum) and (TEnd <> 0)) do

  begin

  TEnd := Pos(SepChar,aString);

  if TEnd <> 0 then

  begin

  Token := Copy(aString,1,TEnd-1);

  Delete(aString,1,TEnd);

  Inc(TNum);

  end

  else

  begin

  Token := aString;

  end;

  end;

  if TNum >= TokenNum then

  begin

  GetToken1 := Token;

  end

  else

  begin

  GetToken1 := '';

  end;

end;

 

function NumToken(aString, SepChar: String):Byte;

{

parameters: aString : the complete string

  SepChar : a single character used as separator

  between the substrings

result : the number of substrings

}

 

var

  RChar : Char;

  StrLen : Byte;

  TNum : Byte;

  TEnd : Byte;

 

begin

  if SepChar = '#' then

  begin

  RChar := '*'

  end

  else

  begin

  RChar := '#'

  end;

  StrLen := Length(aString);

  TNum := 0;

  TEnd := StrLen;

  while TEnd <> 0 do

  begin

  Inc(TNum);

  TEnd := Pos(SepChar,aString);

  if TEnd <> 0 then

  begin

  aString[TEnd] := RChar;

  end;

  end;

  NumToken1 := TNum;

end;

 


 function CopyColumn( const s_string: string; c_fence: char; i_index: integer ): string;

var i, i_left: integer;

begin

  result := EmptyStr;

  if i_index = 0 then begin

  exit;

  end;

  i_left := 0;

  for i := 1 to Length( s_string ) do begin

  if s_string[ i ] = c_fence then begin

  Dec( i_index );

  if i_index = 0 then begin

  result := Copy( s_string, i_left + 1, i - i_left - 1 );

  exit;

  end else begin

  i_left := i;

  end;

  end;

  end;

  Dec( i_index );

  if i_index = 0 then begin

  result := Copy( s_string, i_left + 1, Length( s_string ));

  end;

end;


I know that in GetToken SepChar parameter ( c_fence in my case ) is string, not char, but comment says that he is expecting single char in that string, and it is obvious that if you send more than one char, it won't work correctly. ( Delete(aString,1,TEnd) is buggy if Length( SepChar ) > 1 ).