1

|の間の単語だけを表示する方法を理解しようとしています。および| 以下のXMLの説明にあります。たとえば、「web」または「VideoGames」という単語。

私はこれを試しましたが、単語ごとに長さが異なるため、失敗しました。また、私は|を取り除くことができません

<cfoutput>#Right(thefeed2.rsschannel.eachresult.resultnumber[x].metadata.xmlAttributes.v, 10)#</cfoutput>

私も反対のタスクを実行しようとしています-|の間の単語を除外します および| そのため、表示されません。言い換えれば、最初の項目を例にとると、「web」または「VideoGames」という単語を除いた説明全体を表示します。

私はこれを試しましたが、繰り返しますが、説明だけを除外しようとするのと同じ問題があります。および|。

<cfoutput>#left(thefeed2.rsschannel.eachresult.resultnumber[x].metadata.xmlAttributes.v, 500)#</cfoutput>

だから私の質問は...

1:|の間の単語を抽出するにはどうすればよいですか?および| description要素から。

2:番号1とは別のインスタンスで、|の間の単語を削除するにはどうすればよいですか。および| 説明に?

ちなみに「thefeed2」は私がXMLフィードと呼んでいるものです。

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<rsschannel>
<resultsnumbertotal>11    </resultsnumbertotal>
<eachresult>
<resultnumber N="1">
<U>/file.cfm?id=yahoocom    </U>
<T>Yahoo    </T>
<metadata N="description" V="Quickly find what you're searching for, get in touch with friends and stay in-the-know |Web|"/>
</resultnumber>

<resultnumber N="2">
<U>/file.cfm?id=halo    </U>
<T>Halo    </T>
<metadata N="description" V="Halo is a multi-billion dollar science fiction video game franchise created by Bungie and now managed by 343 Industries and owned by Microsoft Studios. |VideoGames|"/>
</resultnumber>

<resultnumber N="3">
<U>/file.cfm?id=bingcom    </U>
<T>Bing    </T>
<metadata N="description" V="Bing is a search engine that brings together the best of search and people in your social networks to help you spend less time searching and more time doing. |Web|"/>
</resultnumber>

<resultnumber N="4">
<U>/file.cfm?id=lal    </U>
<T>Lakers    </T>
<metadata N="description" V="The Los Angeles Lakers are an American professional basketball team based in Los Angeles, California. They play in the Pacific Division |Sports|"/>
</resultnumber>

<resultnumber N="5">
<U>/file.cfm?id=quick    </U>
<T>Stay in the Know    </T>
<metadata N="description" V="Quickly find what you're searching for, get in touch with friends and stay in-the-know |Misc|"/>
</resultnumber>

<resultnumber N="6">
<U>/file.cfm?id=multi    </U>
<T>Billion Dollars    </T>
<metadata N="description" V="Halo is a multi-billion dollar science fiction video game franchise created by Bungie and now managed by 343 Industries and owned by Microsoft Studios. |Misc|"  />
</resultnumber>

<resultnumber N="7">
<U>/file.cfm?id=searching    </U>
<T>Searches    </T>
<metadata N="description" V="Bing is a search engine that brings together the best of search and people in your social networks to help you spend less time searching and more time doing. |Web|" />
</resultnumber>

<resultnumber N="8">
<U>/file.cfm?id=LosAngeles    </U>
<T>Los Angeles    </T>
<metadata N="description" V="The Los Angeles Lakers are an American professional basketball team based in Los Angeles, California. They play in the Pacific Division |Sports|"/>
</resultnumber>

<resultnumber N="9">
<U>/file.cfm?id=quick    </U>
<T>Stay in the Know    </T>
<metadata N="description" V="Quickly find what you're searching for, get in touch with friends and stay in-the-know |Misc|"/>
</resultnumber>

<resultnumber N="10">
<U>/file.cfm?id=LosAngeles    </U>
<T>Los Angeles    </T>
<metadata N="description" V="The Los Angeles Lakers are an American professional basketball team based in Los Angeles, California. They play in the Pacific Division"/>
</resultnumber>

<resultnumber N="11">
<U>/file.cfm?id=quick    </U>
<T>Stay in the Know    </T>
<metadata N="description" V="Quickly find what you're searching for, get in touch with friends and stay in-the-know |SummaryofDescription|"/>
</resultnumber>

</eachresult>
</rsschannel>
4

3 に答える 3

1

|常に2つのシンボルしかありませんか?もしそうなら、あなたGetTokenは値を見つけるために使用することができます

<cfset Mystring = GetToken(variable,1,'|') />

GetToken変数を区切り文字が|

使用できる単語を削除するにはreplace(variable,Mystring,'')

于 2012-10-04T00:42:32.960 に答える
1

REreplace()で正規表現を使用したいとします。例(cfscript内):

1)

origString = thefeed2.rsschannel.eachresult.resultnumber[x].metadata.xmlAttributes.v;
newString = REreplace(origString, "\|.*\|", "new text");

2)

origString = thefeed2.rsschannel.eachresult.resultnumber[x].metadata.xmlAttributes.v;
newString = REreplace(origString, "\|.*\|", "");

正規表現\|.*\|は、|で始まり|で終わるすべてのテキストと一致します。

于 2012-10-04T00:45:02.520 に答える
1

これはどう。文字列操作の場合は、常に一歩下がって、創造性を発揮するのに役立つパターンを探します。たとえば、CFMLの「リスト」の概念は楽しい時間を作ります。上級ユーザーは常に正規表現に直接向かいますが、始めたばかりの場合、これは間違いなく上級トピックです。すぐに、私はあなたの文字列がパイプ(|)で区切られたリストであると認識しました。また、文はスペースで区切られた単語のリストであることがわかります。ここにいくつかのコードがあります。

 //set your string to something
 <cfset myString = "thefeed2.rsschannel.eachresult.resultnumber[x].metadata.xmlAttributes.v" />
//now let's treat the phrase as a list, we'll get position 2 of the list.
<cfset myWord = listGetAt(myString,2,'|');
//assuming you don't want the pipes in the clean string, let's just do a fast replace once
<cfset cleanString = replace(myString,"|#myWord#|","") />
//if you do want the pipes then you'll need a regex (a more advanced topic)
<cfset cleanStringWithPipes = rereplace(myString,"(\|)[ A-Za-z0-9]+(\|)","\1\2") />
于 2012-10-04T00:49:30.467 に答える