Recent

Author Topic: [SOLVED]Lastdelimiter returns a weird position, but worked correctly at Extrac  (Read 1667 times)

br4d

  • New Member
  • *
  • Posts: 26
I am trying to figure out what is wrong with LastDelimiter function.

This code take a String from a comboBox and extract the ID  inside a bracket pair.
Also variable pos which read the LastDelimiter + 1 should return 5.
But pos is 10 (which is exactly (or coincidently) the length of the catStr.

Also the next ExtractSubstr should return an error or empty string. But the result is correct 567.

Where does the magic come from?

Code: Pascal  [Select][+][-]
  1. //  catStr := cbCategories.Items[cbCategories.ItemIndex];
  2. //  catStr:= 'SOFTEX (1900)';
  3.   catStr:= '0123(567)9';
  4.   pos:=LastDelimiter('(', catStr)+1;
  5.   catID:= ExtractSubstr(catStr, pos,[')']);
  6.   ShowMessage('String = ' + catStr + '. ( found at ' + intToStr(pos) + '. Subword is ' + catID);
  7.  

Thanks,
Brad
« Last Edit: February 19, 2022, 03:30:50 am by br4d »

bytebites

  • Hero Member
  • *****
  • Posts: 778
There is nothing wrong.
Code: Pascal  [Select][+][-]
  1. pos:=LastDelimiter('(', catStr)+1;
pos is 6.
ExtractSubstr changes pos value.

br4d

  • New Member
  • *
  • Posts: 26
Oops thanks. I didn't check that the start position is passed as var.


 

TinyPortal © 2005-2018