如何从url获取特定字符串 [英] How get particular string from url
问题描述
嗨朋友们,
i想要一个网址中的特定价值如下例所示
response = 1&responsetext = SUCCESS&authcode = 123478756&transactionid = 6667666&avsresponse =&cvvresponse =&orderid =&type = sale&response_code = 17800&amount = 00&amount_authorized = 00.00&surcharge = 0.00
在此链接中我想要成功和2699489421 价值如何得不到
谢谢
if (Request.QueryString [ responsetext] != null )
{
string responseText = Request.QueryString [ responsetext]。ToString();
}
类似于transactionid使用Request.QueryString [ transactionid]。ToString()
如果您通过POST方式发送这些,那么它将是
Request.Form [ transactionid]。ToString()
使用Javascript它
function getParameterByName(name){
name = name.replace(/ [\ [] /, \\ [)。 replace(/ [\]] /, \\]);
var regex = new RegExp ( [\\?&] + name + =([^&#] *)),
results = regex.exec(位置跨度> .search);
返回结果=== null ? :decodeURIComponent(results [ 1 ] .replace(/ \ + / g, ));
}
调用此功能:
var responseText = getParameterByName(' responseText的'跨度>);
var transactionId = getParameterByName(' transactionid' );
加载方式:如果您在页面中,可以通过Request.QueryString集合检索它们:使用QueryString在页面之间传递变量 [ ^ ]显示示例。
如果你只有原始字符串并想要提取它们,那么要在&符号上拆分字符串:
string [] keyValuePairs = input.Split(' &') ;
然后在等号上拆分每一个并比较字符串s:
foreach ( string kvp keyValuePairs)
{
string [] kv = kvp.Split(< span class =code-string>' =');
if (kv.Length == 2 )
{
switch (kv [ 0 ]。ToLower())
{
case responsetext:
Console .WriteLine( 响应:{0},kv [ 1 跨度>]);
break ;
case authcode :
Console.WriteLine( Auth:{0],kv [ 1 跨度>]);
break ;
}
}
}或者你可以使用正则表达式:
((?< RESP> *);(小于= responseText的=?)|。?(小于?验证>(小于= AUTHCODE =?)*))(&安培; |。?
hi friends,
i want particular value from a url like below example
response=1&responsetext=SUCCESS&authcode=123478756&transactionid=6667666&avsresponse=&cvvresponse=&orderid=&type=sale&response_code=17800&amount=00&amount_authorized=00.00&surcharge=0.00
in this link i want "Success" and "2699489421" value how cant i get
thanks
if(Request.QueryString["responsetext"]!=null) { string responseText = Request.QueryString["responsetext"].ToString(); }
similarly for transactionid useRequest.QueryString["transactionid"].ToString()
If you are sending these via POST method then it will be
Request.Form["transactionid"].ToString()
Use Javascript for it
function getParameterByName(name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search); return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); }
call this function:
var responseText= getParameterByName('responsetext'); var transactionId= getParameterByName('transactionid');
Loads of ways: if you are in the page you can retrieve them via the Request.QueryString collection: Passing variables between pages using QueryString[^] shows examples.
If you just have the raw string and want to extract them, then either split the string on the ampersand:
string[] keyValuePairs = input.Split('&');
And then split each of those on the equals sign and compare the strings:
foreach (string kvp in keyValuePairs) { string[] kv = kvp.Split('='); if (kv.Length == 2) { switch (kv[0].ToLower()) { case "responsetext": Console.WriteLine("Response: {0}", kv[1]); break; case "authcode": Console.WriteLine("Auth : {0]", kv[1]); break; } } }Or you could use a regex:
((?<Resp>(?<=responsetext=).*?)|(?<Auth>(?<=authcode=).*?))(&|
这篇关于如何从url获取特定字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!