我有我在AutoCAD中捕獲的文本的字符串(0.000000, 0.000000, 0.000000)
這將保存到名爲position.txt的基於文本的文件。修改/刪除文本中的字符從txt文件使用vb.net
因爲您可能已經收集了諸如position.txt之類的文件名,文本可以由任意隨機數組合組成,例如:(5.745379,0.846290,150.6459046)。
但是,它對我有任何用處我需要捕獲的字符串存在沒有空格或括號如何才能在VB.net中實現此目的?
我有我在AutoCAD中捕獲的文本的字符串(0.000000, 0.000000, 0.000000)
這將保存到名爲position.txt的基於文本的文件。修改/刪除文本中的字符從txt文件使用vb.net
因爲您可能已經收集了諸如position.txt之類的文件名,文本可以由任意隨機數組合組成,例如:(5.745379,0.846290,150.6459046)。
但是,它對我有任何用處我需要捕獲的字符串存在沒有空格或括號如何才能在VB.net中實現此目的?
使用String.Replace。它可能不是最有效的方式,但它可以完成工作。
Dim file as String = My.Computer.FileSystem.ReadAllText("position.txt")
Dim output as String = file.Replace(" ", "") _
.Replace("(", "") _
.Replace(")", "")
My.Computer.FileSystem.WriteAllText("output.txt", output, false)
如上
s = "(5.745379, 0.846290, 150.6459046)"
s = s.replace("(","")
s = s.replace(")","")
然後
dim answer() as string = s.split(",")
dim number as double
For each a as string in answer
if double.tryparse(a,n) then
console.writeline(n.tostring & " is a number")
else
console.writeline(n.tostring & " is rubbish")
next
豈不一個的AutoLISP溶液更爲有用? – 2010-11-29 10:32:28
您想將「(5.745379,0.846290,150.6459046)」轉換爲「5.7453790.846290150.6459046」嗎? – smirkingman 2010-11-29 11:24:28