相当于Scheme中Java的IndexOf()?
我正在Scheme中开发一个小程序,但我陷入了困境。有没有类似于Java的indexOf()的东西可以在Scheme中使用?
I am developing a small program in Scheme but I got stuck. Is there anything similar to Java's indexOf() that I could use in Scheme?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
可能有,但通常教授希望你自己写。
这是 C 风格的伪代码,因为我不想记住语法。
请注意,调用它需要为 i 传入 0(如果您愿意,您可以编写一个包装器),并且这是基于 1 的索引,如果您想要基于 0 的索引,请将返回值更改为 i
There may be, but typically professors want you to write your own.
Here is C style psuedo code since I don't want to remember the syntax.
Note that calling it requires passing in 0 for i (You could write a wrapper if you like), and that this is 1 based indexing, change the return to be i if you want 0 based indexing
假设您尝试在字符串中搜索(并且这不是旨在帮助您理解递归的作业),那么您可以尝试此处的函数:
http://okmij.org/ftp/Scheme/util.html
Assuming you're trying to search in strings (and that it's not an assignment intended to help you grok recursion) then you might try the functions here:
http://okmij.org/ftp/Scheme/util.html
从您的问题中不清楚您正在使用什么方案实现。
如果是 PLT 方案,您可能正在寻找类似“regexp-match-positions”的内容。
=>
It's not clear from your question what Scheme implementation you're using.
If it's PLT Scheme, you're probably looking for something like "regexp-match-positions".
=>
例如,在 PLT-Scheme 中,方法是使用 string->list 将字符串转换为列表,然后使用许多可用方法之一对列表进行操作。完成后将列表转换回字符串。
For instance in PLT-Scheme, the way to go is to convert the string to a list using string->list and then operating on the list with one of the many available methods. Convert the list back to a string when done.
搜索列表(相当安全):
Searching list (pretty safe):