How to replace old ParamText/StandartAlert with newer CFString replacements?
ParamText()
is an really old way of replacing parameters in a string that is based on Pascal strings. Also StandardAlert
is not quite Unicode ready.
The new message box (not so new) replacement is CFUserNotificationDisplayNotice
but this one expects CFString
and I found out that if I开发者_如何学C'm about to switch to using CFString I'm not able to use ParamText parameter replacement anymore.
Str255 alertString; // PascalString, yuck!
ParamText(NULL, NULL, minString, maxString);
localize( "A value between ^2 and ^3 is required.", &alertString );
StandardAlert( kAlertNoteAlert, (const unsigned char *)&alertString, nil, nil, &itemHit );
I found out that ParamText
doesn't work with the new dialogs anymore and that Apple forgot to specify how to use them.
Is there any replacement available that would not require me to change the original parameters format in strings?
I found myself a solution but I'm not quite pleased about it.
CMutableStringRef alertString2;
...
alertString2 = CFStringCreateMutableCopy(NULL, CFStringGetLength(alertString), alertString);
CFStringFindAndReplace( alertString2,
CFSTR("^2"),
minRange, // another CFString
CFRangeMake(0, CFStringGetLength(alertString2)),
0);
精彩评论