如何在不同字符串中找到特定字符串位置的特定值 [英] How to find specific VALUE to specific STRING location in different strings

查看:28
本文介绍了如何在不同字符串中找到特定字符串位置的特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的刺
,x,x,y,x,x,O,x,y
与它在另一个这样的刺中的值相匹配
0~1~b~~z~XY~1~7.
值O"可以切换它在字符串中的位置,就像另一个字符串中的值一样.
值O"位于第 6 个位置,因此预期结果将为XY".
第一个字符串总是在每个值之前以,"开头.第二个字符串首先以值开头,后跟~".
O"是一个不会改变的给定值,所以我总是必须在第二个字符串中找到O"所在位置的给定值.

I have a sting like this
,x,x,y,x,x,O,x,y
that matches to its values in an other sting like this
0~1~b~~z~XY~1~7.
The value "O" can switch its position in the string, as will the value in the other string.
The value "O" is in the 6th position so the expectet result would be "XY".
The first string always begins with a "," before each value. The second string starts first with the value followed by the "~".
"O" is a given value which will not change, so I always have to finde the given value for the position wher "O" is, in the second string.

这就是我要表达的:

,x,x,y,x,x,O,x,y
0~1~b~~z~XY~1~7

O=XY


,x,O,y,x,x,y,x,y
0~1~b~~z~XY~1~7

O=1

谢谢.

This ist what I am expexting:

,x,x,y,x,x,O,x,y
0~1~b~~z~XY~1~7

O=XY


,x,O,y,x,x,y,x,y
0~1~b~~z~XY~1~7

O=1

Thank you.

推荐答案

获取一份 DelimitedSplit8K 然后你可以这样做:

Grab a copy of DelimitedSplit8K then you can do this:

DECLARE @string1 VARCHAR(1000) = ',x,x,y,x,x,O,x,y',
        @string2 VARCHAR(1000) = '0~1~b~~z~XY~1~7';

DECLARE @search VARCHAR(1000) = 'O'; -- best as a variable/parameter

SELECT *
FROM dbo.delimitedSplit8K(@string2,'~') AS s
WHERE s.itemNumber = 
(
  SELECT TOP (1) s2.itemNumber -- TOP (1) until we know about dupicates
  FROM   dbo.delimitedSplit8K(@string1,',') AS s2
  WHERE  s2.item = @search
)-1;

退货:

ItemNumber           Item
-------------------- -------
6                    XY

这篇关于如何在不同字符串中找到特定字符串位置的特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆