Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Integer value into AnsiString in Delphi 2009

IntToStr() function returns string which is Unicode now. I want to convert to AnsiString. Can I use AnsiString(IntToStr(I)) safely?

like image 920
user42065 Avatar asked Apr 19 '26 06:04

user42065


2 Answers

Sure. Or you can use IntToAnsiString (written by Dr. Bob):

function IntToAnsiStr(X: Integer; Width: Integer = 0): AnsiString;
begin
   Str(X: Width, Result);
end;
like image 82
gabr Avatar answered Apr 20 '26 19:04

gabr


Yes, you can safely convert the UnicodeString returned by IntToStr to an AnsiString. The reason it's safe is that the string it returns will only contain the digit characters '0' through '9', not any fancy Unicode digits, so the conversion to AnsiString will not lose any information.

like image 45
Rob Kennedy Avatar answered Apr 20 '26 19:04

Rob Kennedy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!