如何用较新的 CFString 替代品替换旧的 ParamText/StandartAlert?

发布于 2024-08-17 15:06:37 字数 652 浏览 3 评论 0原文

ParamText() 是一种非常古老的替换基于 Pascal 字符串的字符串中的参数的方法。另外,StandardAlert 还没有完全支持 Unicode。

新的消息框(不是那么新)的替代品是 CFUserNotificationDisplayNotice 但这个需要 CFString 并且我发现如果我要切换到使用 CFString 我不会能够再使用 ParamText 参数替换。


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 );

我发现 ParamText 不再适用于新对话框,而且 Apple 忘记指定如何使用它们。

是否有任何可用的替代方案不需要我更改字符串中的原始参数格式?

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'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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独陪着我 2024-08-24 15:06:37

我找到了自己的解决方案,但我对此不太满意。


CMutableStringRef alertString2;
...
alertString2 = CFStringCreateMutableCopy(NULL, CFStringGetLength(alertString), alertString);
CFStringFindAndReplace( alertString2, 
        CFSTR("^2"), 
        minRange,  // another CFString
        CFRangeMake(0, CFStringGetLength(alertString2)),
        0);

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);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文