有没有办法在Swift中自动转义字符?
var myString = someMagicWord("#%"$@\/")
在c#中,someMagicWord = @
在Android工作室中,您可以粘贴您的奇怪字符串,ide会自动为您转义字符。
添加@ zaph的示例:有一个文件包含换行符“\ n”,tab“\ t”等字符。打开文件,选择全部,复制,转到Xcode并粘贴到字符串语句中,如@ “pasted_code_here”。 OP希望这些字符自动转义为:@“\ n \ t”
答案 0 :(得分:0)
借助Swift 5,您可以像这样使用原始字符串
var myString = #"#%"$@\/"#
答案 1 :(得分:-1)
虽然在某些语言中,这是可行的(例如:python)在swift"逃避"这些特殊字符实际上是不可能的,因为tablines : \t
,#gdata is a package that contains tools for data manipulation, example: read.xls
library('gdata')
#Creates xls file global variables
filePath = "..."
filenames = list.files(path = filePath, pattern = '[.]xls', recursive = F)
#Initializes final data frame structure
finaldf = data.frame(integer(0))
#List of columns needed output files
listOfColumns = c("Time", "CT Depth", "CT Pressure", "CT Pipe Weight", "CT Running Speed", "Fluid Rate", "Wellhead Pressure","CT PIPE WEIGHT-PIPE HEAVY (lbf)","CT PIPE WEIGHT-PIPE LIGHT (lbf)","FLUID RATE (bpm)")
for (idx in 1:length(filenames)) {
print(idx)
filenamePath = paste(filePath, filenames[idx], sep = "")
df = read.xls(xls = filenamePath , sheet = 1, header = TRUE, verbose = TRUE, check.names = FALSE)
df2 = data.frame(Time = df$Time)
for (jdx in 1:length(listOfColumns)) {
if (is.null(df[[listOfColumns[jdx]]])) {
df2[[listOfColumns[jdx]]] = NA
} else { df2[[listOfColumns[jdx]]] = df[[listOfColumns[jdx]]]}
}
if (nrow(finaldf) == 0) {
finaldf = df2
} else {
finaldf = rbind(finaldf, df2)
}
}
等是字符串文字。你可以看看这个