[英]Saving an Array as Textfile in Visual Basic
我正在嘗試將尺寸為4x1
的數組(聲明為double)保存為文本文件(.txt)
。 分配值后,我使用".ToString"
將數組轉換為字符串。
Dim flowl = New Double() {129.5, 55.33, 0, 12.65}
Dim flowt As String = flowl.ToString
然后,我嘗試使用".WriteAllText"
將該“ flowt
”字符串數組另存為文本文件。 但是在文本文件中它保存了“ system.double[]
”。 有人可以建議我如何避免這種情況嗎? 還是有其他更好的方法將數組另存為文本文件?
先感謝您.......
因為變量起初只是數據結構而不是值,所以輸出到字符串僅返回對象。
如果要使用完全相同的格式,請嘗試
'' some way to tell the index because there seems to be no .Index
Dim item_no As Integer = 0
'' start the output
Dim out As String = "{";
'' iterate through data in the array!!
For Each item As Double In flowl
out += item
'' get next index (prematurely)
item_no += 1
'' before actually getting next item, check if index now equals length
If item_no = flowl.Length Then
'' output close bracket
out += "}"
Else
out += " ," '' output delimiter
End If
Next '' end of for
您可以自己修復它。 同樣,除非您需要專門轉換某些內容或傳達類型,否則並非總是需要As語句。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.