我需要在字符串
中添加'\'我试试这个
var Filename = name.Replace("'", "\'");
name = Filename ;
如果名字=他在这里
name.Replace(“'”,“\'”)将返回:“他在这里”
我需要的是:他在这里
答案 0 :(得分:0)
首先import numpy as np
import cv2
from matplotlib import pyplot as plt
from matplotlib import image as image
I = image.imread('test.jpg') # read image
G = cv2.cvtColor(I, cv2.COLOR_BGR2GRAY) # convert 3D matrix to 2D
# Canny Edge Detection:
Threshold1 = 100;
Threshold2 = 100;
FilterSize = 5
E = cv2.Canny(G, Threshold1, Threshold2, FilterSize)
# Hough line transform
lines = cv2.HoughLinesP(E,rho = 1,theta = 0.1*np.pi/180,threshold = 1,
minLineLength = 1, maxLineGap = 1)
# Plot the hough line in original image
N = lines.shape[0]
for i in range(N):
x1 = lines[i][0][0]
y1 = lines[i][0][1]
x2 = lines[i][0][2]
y2 = lines[i][0][3]
cv2.line(I,(x1,y1),(x2,y2),(255,0,0),2)
plt.figure(),plt.imshow(I),plt.title('Hough Lines'),plt.axis('off')
无效,因为name.Replace("'", "\'")
。所以"'" == "\'"
会返回“他在这里”(你可以在https://dotnetfiddle.net/中尝试)。你想要的是:name.Replace("'", "\'")
如果您在调试器中检查名称(在监视窗口或即时窗口中),您将获得name.Replace("'", "\\'")
,因为这是您应该在c#中编写字符串常量以将"he\\'s here"
转换为变量的方式。