如何删除字符串中的转义符

时间:2019-04-11 11:14:11

标签: c# .net

我创建了一个可以接受一个字符串参数的API,但是当我尝试将""用作searchterm时,输出结果会有一个转义字符。我该如何删除?谢谢

searchterm = searchterm.Replace(@"\", String.Empty);

我尝试了这个,但是仍然有转义符。

这是我的代码c#

public static JToken getRelatedKeywordsApiSpTable(string searchterm)
{
  JObject results = new JObject();
  searchterm = searchterm.Replace(@"\", String.Empty);
  DataSet ds = SearchData.getRelatedKeyword(searchterm);
  DynamicCollabObject relatedkeywords = new DynamicCollabObject(ds);
  results.Add("RelatedKeywords", relatedkeywords.dobject);
  return results;
}


public static DataSet getRelatedKeyword(string searchterm)
{
    List<SqlParameter> parameters = new List<SqlParameter>();
    parameters.Add(new SqlParameter("@st", searchterm));
    return SQLDAL.runSPWithParams(SearchSPs.getRelatedKeywordApi, parameters, SearchSettings.badlands);
}

这是我的终点

[HttpGet]
[Route("relatedkeyword/{searchterm}")]
public IHttpActionResult RelatedKeywordApiTable(string searchterm)
{
    return Ok(SearchBusiness.getRelatedKeywordsApiSpTable(searchterm));
}

我的SP

select top 20 relatedkeyword as Keyword, [count] as [Count] 
from Transform_DIM_RelatedKeyword_Count  WITH (NOLOCK)
where searchterm=@st 
order by count desc

输出:

{
  "RelatedKeywords": [
    {
      "Keyword": "\"\"",
      "Count": 7
    }
    ]
}

How i view the request

我的期望应该看起来像实际的输入搜索词

0 个答案:

没有答案