0

任何人都可以帮助我,因为我需要在之后提取数字"Reference=" in the enclosed?不可能知道数字之前或之后的字符数以及数字的长度(也可以是字母和数字),但它总是

After "Reference=" Before ",Description"

Object=CTSENORaanG,Reference=0000021357,Description=Test,Currency=EUR,Initial_Date=15Aug2011....

该字符串来自具有大量行的表,我需要将每一行的引用插入到另一个表中

4

3 回答 3

2

SQL 服务器

declare @str varchar(1000)
set @str='Object=CTSENORaanG,Reference=0000021357,Description=Test,Currency=EUR,Initial_Date=15Aug2011....';

select substring(col,1,charindex(',',col)-1) from
(
select substring(@str,charindex('Reference=',@str)+10,100) as col
) as t;

MySQL

set @str:='Object=CTSENORaanG,Reference=0000021357,Description=Test,Currency=EUR,Initial_Date=15Aug2011....';

select substring(col,1,locate(',',col)-1) from
(
select substring(@str,locate('Reference=',@str)+10,100) as col
) as t;
于 2012-07-12T07:28:49.017 回答
1

如果分隔符始终是逗号,,则可以拆分字符串。然后,如果分隔的子字符串也与 . 一致,您可以将其进一步拆分=。一旦你捞出来Reference,你会得到它的等值。

/* your test string */
string s = "Object=CTSENORaanG,Reference=0000021357,Description=Test,Currency=EUR,Initial_Date=15Aug2011";     
string[] arr = s.Split(',');

/* will contain the value you're looking for */    
string target = String.Empty;

foreach (string item in arr)
{
   string[] entry = item.Split('=');
   if (entry.Length == 2 && entry[0] == "Reference")
   {
      target = entry[1];
      break;
   }
}
于 2012-07-12T07:18:35.007 回答
0
use
pos = explode(",",string);
foreach(pos as po)
{
    p = explode("=",po)
    i=0;
    foreach(p as a)
    {
        if(a[i]== Reference)
        {
            echo p[i+1];
            i++;
        }
    }
}
于 2012-07-12T07:26:31.970 回答