I'm trying to replace all double quotes in a file but when I try to update the string array I just get the original line again instead of the cleaned string. (The Boolean's in the ReplaceQuotes function are just for testing and they come back true when there's a " in the line). If I look at the cleanLine string, the quotes have been removed, but when I return the fileContent array, it looks just like the original with the quotes.
Private Sub CleanFile(currentFileInfo As FileInfo)
Dim fullName As String = currentFileInfo.FullName
Dim fileContent As String() = GetFileContent(currentFileInfo.FullName)
Dim cleanFileContent As String() = ReplaceQuotes(fileContent)
End Sub
Private Function GetFileContent(fileName As String) As String()
Return System.IO.File.ReadAllLines(fileName)
End Function
Private Function ReplaceQuotes(fileContent As String())
For Each line As String In fileContent
Dim cleanLine As String
Dim quoteTest As Boolean
quoteTest = line.Contains("""")
Dim quoteTest2 As Boolean = line.Contains(ControlChars.Quote)
cleanLine = line.Replace(ControlChars.Quote, "")
line = cleanLine
Next
Return fileContent
End Function
Return fileContentis just what was passed to it.lineis just a local variable which references the string in the array. By re-assigning a new string to that variable you don't change the array.