2

I'm looking for RTL delphi function equivalent to the sscanf/swscanf C++ functions. Exist something like that in the RTL delphi functions or I must look for a third-party implementation?

Salvador
  • 16,132
  • 33
  • 143
  • 245
  • possible duplicate of [Is there an inverse function of *SysUtils.Format* in Delphi](http://stackoverflow.com/questions/72672/is-there-an-inverse-function-of-sysutils-format-in-delphi) – Rob Kennedy Jan 27 '12 at 22:13
  • There's already a similar question, to which I had the pleasure of answering with a bit of code : https://stackoverflow.com/a/72713/12170 – PatrickvL Jan 27 '12 at 21:46

4 Answers4

5

I personally would simply call the real functions which can be imported from msvcrt.dll.

function sscanf(buffer, format: PAnsiChar): Integer; 
    cdecl; varargs; external 'msvcrt.dll';
function swscanf(buffer, format: PWideChar): Integer; 
    cdecl; varargs; external 'msvcrt.dll';

These are tried and tested robust implementations of the C standard library functions.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • 2
    @WarrenP You need not redistribute msvcrt.dll like you need not redistribute kernel32.dll, gdi32.dll, etc. - it is a part of OS Windows. – kludg Jan 28 '12 at 04:16
  • Yes, since Windows 2000, msvcrt is a standard Windows component. It's the C runtime for MSVC6. – David Heffernan Jan 28 '12 at 10:11
1

You can download Scan function for Delphi, which is ported MSVC RTL function.

da-soft
  • 7,670
  • 28
  • 36
0

There's a port of sscanf at http://cc.embarcadero.com/item/24258 but it looks to pre-date Unicode so may need some tweaks for XE.

frogb
  • 2,040
  • 15
  • 22
0

These are deprecated functions even in C. Use something more modern and type-safe to parse your data. This is going to be a rich source of errors in your application. For example, how do you intend to make a (wchar_t *) C style scanf string function interoperate with Delphi Strings?

Warren P
  • 65,725
  • 40
  • 181
  • 316