手動從串
例如讀它,在 「https://blockchain.info/tx/a97aaf679880e079f80ddca53044b8cb3bd511014fb09bd28e33d5430dab4c8e」只讀最後的64個字符。發送代碼總是64個字符。
正則表達式
如果你從哪個你想讀的TX-ID的多個服務/網站,你可以保存其中的Tx-ID開始字符串中的位置,然後讀取64個字符那裏。既然你沒有說你要使用的編程語言,我將展示在C++一個例子:
#include <iostream>
#include <string>
#include <vector>
#include <regex>
using namespace std;
struct PositionInString
{
PositionInString(string h, unsigned int p) : host(h), position(p) {}
string host;
unsigned int position;
};
int main()
{
vector<PositionInString> positions;
positions.push_back(PositionInString("blockchain.info", 27));
positions.push_back(PositionInString("btc.blockr.io", 30));
while(true)
{
string url;
cout << "Enter url: ";
cin >> url;
regex reg_ex("([a-z0-9|-]+\\.)*[a-z0-9|-]+\\.[a-z]+");
smatch match;
string extract;
if (regex_search(url, match, reg_ex))
{
extract = match[0];
}
else
{
cout << "Could not extract." << endl;
continue;
}
bool found = false;
for(auto& v : positions)
{
if(v.host.compare(extract) == 0)
{
cout << "Tx-Id: " << url.substr(v.position, 64) << endl;
found = true;
break;
}
}
if(found == false)
cout << "Unknown host \"" << extract << "\"" << endl;
}
return 0;
}
輸出:
Enter url: https://blockchain.info/tx/a97aaf679880e079f80ddca53044b8cb3bd511014fb09bd28e33d5430dab4c8e
Tx-Id: a97aaf679880e079f80ddca53044b8cb3bd511014fb09bd28e33d5430dab4c8e
歡迎堆棧溢出!我編輯了問題的格式以提高可讀性,這可能會增加接收有用答案的可能性。 –