PostScript 字符串转换失败 - 无法捕获/类型检查错误

发布于 2025-01-12 05:52:59 字数 408 浏览 4 评论 0原文

我想检查函数中最上面参数的类型,如果它的类型是字符串,则将其转换为 int。如果字符串包含字母,我会收到 /typecheck 错误。我的代码是:

/doConvert {
    dup type /stringtype eq { cvi } if
...
} def

现在我可以将值保存在变量中并执行类似的操作:

/a exch def a type /stringtype eq { {a cvi} stopped {pop 0} if} if

在不使用变量的情况下可以获得相同的结果吗?我尝试过使用 cvxexec 但我总是收到 /typecheck 错误,因为我没有在大括号中进行类型转换。

I want to check the type of the top most parameter in my function and convert it to int if it's type is string. If the string contains letters I get a /typecheck error. My code is:

/doConvert {
    dup type /stringtype eq { cvi } if
...
} def

Now I can save the value in a variable and do something like this:

/a exch def a type /stringtype eq { {a cvi} stopped {pop 0} if} if

Can I get the same result without using variables? I have tried using cvx and exec but I always get the /typecheck error because I do not have the type conversion in curly brackets.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文