我需要管理'AccountText'变量,所以如果我传递一个带有特殊字符的值作为例如“MC& CO”,我不应该出错。
import math
# Define variables and create the grid
a = 0
b = 2
rounds = 5
# Size of the grid
y_max, x_max = 100, 100
# Center of the grid
origo_y, origo_x = 50, 50
# Every element in the grid is truly unique element
# If the grid is created like this
# Don't use for example [[" "]*x_max]*y_max
grid = [[" " for i in range(x_max)] for j in range(y_max)]
for angle in range(rounds*360):
# Calculations for the spiral
rads = math.radians(angle)
r = a + b * rads
y = r * math.sin(rads)
x = r * math.cos(rads)
x_coord = origo_x + round(x)
y_coord = origo_y + round(y)
if (0 <= x_coord < x_max) and (0 <= y_coord < y_max):
grid[y_coord][x_coord] = "#"
# Print the whole grid
for line in grid:
print("".join(line))
答案 0 :(得分:3)
您可以在将AccountText
包含在查询中之前对其进行编码:
AccountText = HttpUtility.HtmlEncode(AccountText);
答案 1 :(得分:1)
据我所知,FetchXML使用XML的本机特殊字符处理,因此您可以将&符号转义为&
例如:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >
<entity name="account" >
<attribute name="accountid" />
<filter type="and" >
<condition attribute="name" operator="eq" value="MC&Co" />
</filter>
</entity>
</fetch>
要为所有特殊字符执行此操作,有几种方法可以转义XML的字符串。最快的可能是使用System.Web
库中的System.Security.SecurityElement.Escape()方法:
string xml = "<node>it's my \"node\" & i like it<node>";
string encodedXml = System.Security.SecurityElement.Escape(xml);
输出:
<node>it's my "node" & i like it<node>
还有更多示例here