Page 1 of 1

'LastDelimter' on string or ' .DelimitedText' on TStringList

Posted: Sun Dec 18, 2011 7:04 pm
by nycfella
I am a total noob to the forum and to Delphi. I have been able to use some of the sample scripts to manipulate some strings (copy, trim, etc). I am trying to develop a script that uses 'LastDelimiter' on the Artist field to return the postion of the last space in an artist name. From there, I hope to get the last name of the artist regardless of the number of spaces in the name (i.e. "Jimi Hendrix" returns "Hendrix", "Stevie Ray Vaughan" returns "Vaughan", "George 'The Animal' Steele" returns "Steele", etc.)

My first attempts result in compile error: 'Unknown dentifier: LastDelimiter'

I'd also looked at using a TStringList.DelimitedText approach, but haven't attempted it.

I'm mostly trying to find out if LastDelimiter or DelimitedText are supported in TGF. Apologies in advance if this is a really stupid newbie question or syntax. I an clueless, and just want to work within what's supported.

Code: Select all

program LastName;

var
  sTmpArtist : string;
  sTmpLast : string;
  sTmpFull : string;
  iPos : integer;

begin

  if not tg_Init then exit;

  repeat


  sTmpArtist := tg_GetField( 'Artist' );
  iPos := LastDelimiter(' ', sTmpArtist);



  until not tg_Skip;


end;

Re: 'LastDelimter' on string or ' .DelimitedText' on TString

Posted: Mon Dec 19, 2011 3:26 pm
by jtclipper
You can use the Rpos function to get the position of the last delimiter.

Code: Select all

 // this will also extract the last part of the artist field  
 Copy( tg_getField( 'Artist' ), RPos( ' ', tg_getField( 'Artist' ) ) + 1, 999 ) );