问题描述
在字符串中定位第三个空格的索引的最简单方法是什么.
What would be the simplest way to locate the index of the third space in a string.
我的目标是从空格分隔的列表AAAA BBBB CCCC DDDD EEE
中删除CCC
.其中A和B和D是固定长度,C是可变长度,E F G是可选的.
My goal is to get CCC
out of this space separated list: AAAA BBBB CCCC DDDD EEE
. where A and B and D are fixed length, and C is variable length, E F G are optional.
在Java中,我将使用indexof,起始点为10,这将使我获得第三个空格,但是似乎我无法在MySQL中做到这一点,所以我认为也许可以找到函数的第三个索引" ?
In Java I would use indexof, with a starting point of 10 and that would get me the third space, but it seems that I cannot do that in MySQL, so I thought maybe I could find a 'third index of' function?
推荐答案
您希望使用这样的SUBSTRING_INDEX
函数
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(field, ' ', 3), ' ', -1)
FROM table
内部函数调用会将您带至AAAA BBBB CCCC
,而外部函数调用会将其降低至CCCC
.
The inner function call would get you to AAAA BBBB CCCC
while the outer function call would pare that down to just CCCC
.
这篇关于MySQL字符串中的第二(或第三)索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!