MySQL 字符串的最后一个索引

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5796340/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:39:39  来源:igfitidea点击:

MySQL String Last Index Of

mysqlstringindexof

提问by Bryan Field

I am able to use LOCATEto get the index of a character such as a .in www.google.com. Thus I can use substring to strip out everything before the first ..

我可以用来LOCATE获取字符的索引,例如 a .in www.google.com。因此,我可以使用 substring 在第一个..

Is there a way I can look for the last/?

有没有办法可以找到最后一个/

So I can get test.htmout of http://www.example.com/dev/archive/examples/test.htm?

所以我可以test.htm出去http://www.example.com/dev/archive/examples/test.htm吗?

I do not want to say the 6th slash, I want to say the last slash. Can this be done?

我不想说第6个斜线,我想说最后一个斜线。这能做到吗?

回答by Nicola Cossu

Use substring_index

使用 substring_index

select substring_index('http://www.example.com/dev/archive/examples/test.htm','/',-1)