How can I extract a substring?

I have function in delphi

function GetHardDiskSerial(const DriveLetter: Char): string; var NotUsed: DWORD; VolumeFlags: DWORD; VolumeInfo: array[0..MAX_PATH] of Char; VolumeSerialNumber: DWORD; begin GetVolumeInformation(PChar(DriveLetter + ':\'), nil, SizeOf(VolumeInfo), @VolumeSerialNumber, NotUsed, VolumeFlags, nil, 0); Result := Format('%8.8X', [VolumeSerialNumber]) end; 

how to take the output character to 2 up to 4.

Example: 7121334

  • Result must be: 121

cSerial.text=......................................

1 Answer

You can use the Copy function to extract a sequence of characters from a string:

cSerial.Text := Copy(Result, 2, 3); 

Note that the third parameter is the number of characters to extract, not the index of the last character.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like