我有我在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