小编Ash*_*win的帖子

USPS 地址验证 API:如果地址字段中有 & 或 # 符号,则 API 返回错误响应

我编写了一个 C# 代码来访问 USPS 地址验证 API。如果没有 & 或 # 符号,API 将返回正确的响应但是如果请求有 # 或 & 符号,那么我会收到错误响应。

我正在使用 System.Xml.Linq 库来构建一个 XML 字符串。

差异输出。 1) 如果地址包含#

<Error>
  <Number>80040B19</Number>
  <Description>XML Syntax Error: Please check the XML request to see if it can be parsed.(B)</Description>
  <Source>USPSCOM::DoAuth</Source>
</Error>
Run Code Online (Sandbox Code Playgroud)

2) **如果地址包含 & 则转换为 & amp; 通过 XDocument **

<Error>
  <Number>80040B18</Number>
  <Description>An error has occurred with the service.  Please contact the system administrator, or try again.</Description>
  <Source>USPSCom::DoAuth</Source>
</Error>
Run Code Online (Sandbox Code Playgroud)

这是我编写的 C# 代码。

public static XDocument …
Run Code Online (Sandbox Code Playgroud)

c# xml api usps

1
推荐指数
1
解决办法
712
查看次数

在c#中用空字符替换空格

如何用什么都没有替换任何charachter.例如

1 : string inputString = "This Is Stack OverFlow";
2 : string outputString = inputString.Replace(' ', '');

expected output = "ThisIsStackOverFlow";
Run Code Online (Sandbox Code Playgroud)

我尝试过第2行,但它在Replace方法第二个参数中说空字符串.任何人都可以告诉我,我的替换方法有什么问题吗?为什么它不像我们通常在字符串中使用的那样空白(例如:"")?

c#

-1
推荐指数
1
解决办法
6086
查看次数

标签 统计

c# ×2

api ×1

usps ×1

xml ×1