Replace the string data from a file [closed]
so you have pretty much read the title,
I want to make it so that any value in ResolutionSizeX= is going to become 1920 every single number.
Heres my code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
My.Computer.FileSystem.WriteAllText("C:UsersNarpZAppDataLocalFortniteGameSavedConfigWindowsClientGameUserSettings.ini",
My.Computer.FileSystem.ReadAllText("C:UsersNarpZAppDataLocalFortniteGameSavedConfigWindowsClientGameUserSettings.ini").Replace("ResolutionSizeX=", "ResolutionSizeX=1920"),
False)
End Sub
vb.net
closed as unclear what you're asking by David, Ken White, Andrew Morton, IvanH, grizzthedj Jan 2 at 14:56
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
|
show 2 more comments
so you have pretty much read the title,
I want to make it so that any value in ResolutionSizeX= is going to become 1920 every single number.
Heres my code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
My.Computer.FileSystem.WriteAllText("C:UsersNarpZAppDataLocalFortniteGameSavedConfigWindowsClientGameUserSettings.ini",
My.Computer.FileSystem.ReadAllText("C:UsersNarpZAppDataLocalFortniteGameSavedConfigWindowsClientGameUserSettings.ini").Replace("ResolutionSizeX=", "ResolutionSizeX=1920"),
False)
End Sub
vb.net
closed as unclear what you're asking by David, Ken White, Andrew Morton, IvanH, grizzthedj Jan 2 at 14:56
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
What's your question? Is something not working as expected? What isn't working? Which step along the way is the first to fail? (Hint: Separate your operations into individual lines of code to observe them one at a time while debugging.) What data is in your file? Please specify the problem.
– David
Jan 2 at 13:09
I wanted every single number that is possible in it to become 1920, if it is like 1628 or 980 or 16 or 12034 you understand?
– Narpzy
Jan 2 at 13:14
what do you mean about "Can you do it in a text editor which supports regular expressions?"
– Narpzy
Jan 2 at 13:25
check this out to edit INI files - stackoverflow.com/questions/217902/reading-writing-an-ini-file
– Ctznkane525
Jan 2 at 13:33
Im doing this in visual basic. When I tried it, it didn't work.
– Narpzy
Jan 2 at 13:46
|
show 2 more comments
so you have pretty much read the title,
I want to make it so that any value in ResolutionSizeX= is going to become 1920 every single number.
Heres my code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
My.Computer.FileSystem.WriteAllText("C:UsersNarpZAppDataLocalFortniteGameSavedConfigWindowsClientGameUserSettings.ini",
My.Computer.FileSystem.ReadAllText("C:UsersNarpZAppDataLocalFortniteGameSavedConfigWindowsClientGameUserSettings.ini").Replace("ResolutionSizeX=", "ResolutionSizeX=1920"),
False)
End Sub
vb.net
so you have pretty much read the title,
I want to make it so that any value in ResolutionSizeX= is going to become 1920 every single number.
Heres my code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
My.Computer.FileSystem.WriteAllText("C:UsersNarpZAppDataLocalFortniteGameSavedConfigWindowsClientGameUserSettings.ini",
My.Computer.FileSystem.ReadAllText("C:UsersNarpZAppDataLocalFortniteGameSavedConfigWindowsClientGameUserSettings.ini").Replace("ResolutionSizeX=", "ResolutionSizeX=1920"),
False)
End Sub
vb.net
vb.net
edited Jan 2 at 14:32


Visual Vincent
15.5k52052
15.5k52052
asked Jan 2 at 13:07


NarpzyNarpzy
32
32
closed as unclear what you're asking by David, Ken White, Andrew Morton, IvanH, grizzthedj Jan 2 at 14:56
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by David, Ken White, Andrew Morton, IvanH, grizzthedj Jan 2 at 14:56
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
What's your question? Is something not working as expected? What isn't working? Which step along the way is the first to fail? (Hint: Separate your operations into individual lines of code to observe them one at a time while debugging.) What data is in your file? Please specify the problem.
– David
Jan 2 at 13:09
I wanted every single number that is possible in it to become 1920, if it is like 1628 or 980 or 16 or 12034 you understand?
– Narpzy
Jan 2 at 13:14
what do you mean about "Can you do it in a text editor which supports regular expressions?"
– Narpzy
Jan 2 at 13:25
check this out to edit INI files - stackoverflow.com/questions/217902/reading-writing-an-ini-file
– Ctznkane525
Jan 2 at 13:33
Im doing this in visual basic. When I tried it, it didn't work.
– Narpzy
Jan 2 at 13:46
|
show 2 more comments
1
What's your question? Is something not working as expected? What isn't working? Which step along the way is the first to fail? (Hint: Separate your operations into individual lines of code to observe them one at a time while debugging.) What data is in your file? Please specify the problem.
– David
Jan 2 at 13:09
I wanted every single number that is possible in it to become 1920, if it is like 1628 or 980 or 16 or 12034 you understand?
– Narpzy
Jan 2 at 13:14
what do you mean about "Can you do it in a text editor which supports regular expressions?"
– Narpzy
Jan 2 at 13:25
check this out to edit INI files - stackoverflow.com/questions/217902/reading-writing-an-ini-file
– Ctznkane525
Jan 2 at 13:33
Im doing this in visual basic. When I tried it, it didn't work.
– Narpzy
Jan 2 at 13:46
1
1
What's your question? Is something not working as expected? What isn't working? Which step along the way is the first to fail? (Hint: Separate your operations into individual lines of code to observe them one at a time while debugging.) What data is in your file? Please specify the problem.
– David
Jan 2 at 13:09
What's your question? Is something not working as expected? What isn't working? Which step along the way is the first to fail? (Hint: Separate your operations into individual lines of code to observe them one at a time while debugging.) What data is in your file? Please specify the problem.
– David
Jan 2 at 13:09
I wanted every single number that is possible in it to become 1920, if it is like 1628 or 980 or 16 or 12034 you understand?
– Narpzy
Jan 2 at 13:14
I wanted every single number that is possible in it to become 1920, if it is like 1628 or 980 or 16 or 12034 you understand?
– Narpzy
Jan 2 at 13:14
what do you mean about "Can you do it in a text editor which supports regular expressions?"
– Narpzy
Jan 2 at 13:25
what do you mean about "Can you do it in a text editor which supports regular expressions?"
– Narpzy
Jan 2 at 13:25
check this out to edit INI files - stackoverflow.com/questions/217902/reading-writing-an-ini-file
– Ctznkane525
Jan 2 at 13:33
check this out to edit INI files - stackoverflow.com/questions/217902/reading-writing-an-ini-file
– Ctznkane525
Jan 2 at 13:33
Im doing this in visual basic. When I tried it, it didn't work.
– Narpzy
Jan 2 at 13:46
Im doing this in visual basic. When I tried it, it didn't work.
– Narpzy
Jan 2 at 13:46
|
show 2 more comments
1 Answer
1
active
oldest
votes
Untested but it should do the trick.
Dim strFile As String = "C:UsersNarpZAppDataLocalFortniteGameSavedConfigWindowsClientGameUserSettings.ini"
If System.IO.File.Exists(strFile) Then
Dim arrLines() As String = IO.File.ReadAllLines(strFile)
For i As Integer = 0 To arrLines.Length - 1
If Strings.Left(arrLines(i),16)="ResolutionSizeX=" Then
arrLines(i) = "ResolutionSizeX=1920"
End If
Next
System.IO.File.WriteAllLines(strFile, arrLines) 'SAVE
End If
It does the trick, but if I have something named LastUserConfirmedResolutionSizeX it changes that too to ResolutionSizeX.
– Narpzy
Jan 2 at 14:14
@Narpzy adapted the code so it checks if the 16 first chars of the line are ResolutionSizeX=, and not simply contain the string
– Thomas G
Jan 2 at 14:20
I just tried to do the same with LastUserConfirmedResolutionSizeX, and it didn't work, heres the code: If System.IO.File.Exists(strFile) Then Dim arrLines() As String = IO.File.ReadAllLines(strFile) For i As Integer = 0 To arrLines.Length - 1 If Strings.Left(arrLines(i), 16) = "ResolutionSizeX=" Then arrLines(i) = "ResolutionSizeX=1920" ElseIf Strings.Left(arrLines(i), 16) = "LastUserConfirmedResolutionSizeX=" Then arrLines(i) = "LastUserConfirmedResolutionSizeX=1920" End If Next System.IO.File.WriteAllLines(strFile, arrLines) 'SAVE End If
– Narpzy
Jan 2 at 14:28
Remove theFile.Exists()
check. It's almost always counter-productive, and usually makes things slower; you're normally better off just handling the exception.
– Joel Coehoorn
Jan 2 at 14:35
If you want to make it work with other variables, you have to adapt the 16 in the Left instruction. 16 is the number of chars in your string, including the = at the end
– Thomas G
Jan 2 at 14:36
|
show 2 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Untested but it should do the trick.
Dim strFile As String = "C:UsersNarpZAppDataLocalFortniteGameSavedConfigWindowsClientGameUserSettings.ini"
If System.IO.File.Exists(strFile) Then
Dim arrLines() As String = IO.File.ReadAllLines(strFile)
For i As Integer = 0 To arrLines.Length - 1
If Strings.Left(arrLines(i),16)="ResolutionSizeX=" Then
arrLines(i) = "ResolutionSizeX=1920"
End If
Next
System.IO.File.WriteAllLines(strFile, arrLines) 'SAVE
End If
It does the trick, but if I have something named LastUserConfirmedResolutionSizeX it changes that too to ResolutionSizeX.
– Narpzy
Jan 2 at 14:14
@Narpzy adapted the code so it checks if the 16 first chars of the line are ResolutionSizeX=, and not simply contain the string
– Thomas G
Jan 2 at 14:20
I just tried to do the same with LastUserConfirmedResolutionSizeX, and it didn't work, heres the code: If System.IO.File.Exists(strFile) Then Dim arrLines() As String = IO.File.ReadAllLines(strFile) For i As Integer = 0 To arrLines.Length - 1 If Strings.Left(arrLines(i), 16) = "ResolutionSizeX=" Then arrLines(i) = "ResolutionSizeX=1920" ElseIf Strings.Left(arrLines(i), 16) = "LastUserConfirmedResolutionSizeX=" Then arrLines(i) = "LastUserConfirmedResolutionSizeX=1920" End If Next System.IO.File.WriteAllLines(strFile, arrLines) 'SAVE End If
– Narpzy
Jan 2 at 14:28
Remove theFile.Exists()
check. It's almost always counter-productive, and usually makes things slower; you're normally better off just handling the exception.
– Joel Coehoorn
Jan 2 at 14:35
If you want to make it work with other variables, you have to adapt the 16 in the Left instruction. 16 is the number of chars in your string, including the = at the end
– Thomas G
Jan 2 at 14:36
|
show 2 more comments
Untested but it should do the trick.
Dim strFile As String = "C:UsersNarpZAppDataLocalFortniteGameSavedConfigWindowsClientGameUserSettings.ini"
If System.IO.File.Exists(strFile) Then
Dim arrLines() As String = IO.File.ReadAllLines(strFile)
For i As Integer = 0 To arrLines.Length - 1
If Strings.Left(arrLines(i),16)="ResolutionSizeX=" Then
arrLines(i) = "ResolutionSizeX=1920"
End If
Next
System.IO.File.WriteAllLines(strFile, arrLines) 'SAVE
End If
It does the trick, but if I have something named LastUserConfirmedResolutionSizeX it changes that too to ResolutionSizeX.
– Narpzy
Jan 2 at 14:14
@Narpzy adapted the code so it checks if the 16 first chars of the line are ResolutionSizeX=, and not simply contain the string
– Thomas G
Jan 2 at 14:20
I just tried to do the same with LastUserConfirmedResolutionSizeX, and it didn't work, heres the code: If System.IO.File.Exists(strFile) Then Dim arrLines() As String = IO.File.ReadAllLines(strFile) For i As Integer = 0 To arrLines.Length - 1 If Strings.Left(arrLines(i), 16) = "ResolutionSizeX=" Then arrLines(i) = "ResolutionSizeX=1920" ElseIf Strings.Left(arrLines(i), 16) = "LastUserConfirmedResolutionSizeX=" Then arrLines(i) = "LastUserConfirmedResolutionSizeX=1920" End If Next System.IO.File.WriteAllLines(strFile, arrLines) 'SAVE End If
– Narpzy
Jan 2 at 14:28
Remove theFile.Exists()
check. It's almost always counter-productive, and usually makes things slower; you're normally better off just handling the exception.
– Joel Coehoorn
Jan 2 at 14:35
If you want to make it work with other variables, you have to adapt the 16 in the Left instruction. 16 is the number of chars in your string, including the = at the end
– Thomas G
Jan 2 at 14:36
|
show 2 more comments
Untested but it should do the trick.
Dim strFile As String = "C:UsersNarpZAppDataLocalFortniteGameSavedConfigWindowsClientGameUserSettings.ini"
If System.IO.File.Exists(strFile) Then
Dim arrLines() As String = IO.File.ReadAllLines(strFile)
For i As Integer = 0 To arrLines.Length - 1
If Strings.Left(arrLines(i),16)="ResolutionSizeX=" Then
arrLines(i) = "ResolutionSizeX=1920"
End If
Next
System.IO.File.WriteAllLines(strFile, arrLines) 'SAVE
End If
Untested but it should do the trick.
Dim strFile As String = "C:UsersNarpZAppDataLocalFortniteGameSavedConfigWindowsClientGameUserSettings.ini"
If System.IO.File.Exists(strFile) Then
Dim arrLines() As String = IO.File.ReadAllLines(strFile)
For i As Integer = 0 To arrLines.Length - 1
If Strings.Left(arrLines(i),16)="ResolutionSizeX=" Then
arrLines(i) = "ResolutionSizeX=1920"
End If
Next
System.IO.File.WriteAllLines(strFile, arrLines) 'SAVE
End If
edited Jan 2 at 14:19
answered Jan 2 at 14:06


Thomas GThomas G
7,46872033
7,46872033
It does the trick, but if I have something named LastUserConfirmedResolutionSizeX it changes that too to ResolutionSizeX.
– Narpzy
Jan 2 at 14:14
@Narpzy adapted the code so it checks if the 16 first chars of the line are ResolutionSizeX=, and not simply contain the string
– Thomas G
Jan 2 at 14:20
I just tried to do the same with LastUserConfirmedResolutionSizeX, and it didn't work, heres the code: If System.IO.File.Exists(strFile) Then Dim arrLines() As String = IO.File.ReadAllLines(strFile) For i As Integer = 0 To arrLines.Length - 1 If Strings.Left(arrLines(i), 16) = "ResolutionSizeX=" Then arrLines(i) = "ResolutionSizeX=1920" ElseIf Strings.Left(arrLines(i), 16) = "LastUserConfirmedResolutionSizeX=" Then arrLines(i) = "LastUserConfirmedResolutionSizeX=1920" End If Next System.IO.File.WriteAllLines(strFile, arrLines) 'SAVE End If
– Narpzy
Jan 2 at 14:28
Remove theFile.Exists()
check. It's almost always counter-productive, and usually makes things slower; you're normally better off just handling the exception.
– Joel Coehoorn
Jan 2 at 14:35
If you want to make it work with other variables, you have to adapt the 16 in the Left instruction. 16 is the number of chars in your string, including the = at the end
– Thomas G
Jan 2 at 14:36
|
show 2 more comments
It does the trick, but if I have something named LastUserConfirmedResolutionSizeX it changes that too to ResolutionSizeX.
– Narpzy
Jan 2 at 14:14
@Narpzy adapted the code so it checks if the 16 first chars of the line are ResolutionSizeX=, and not simply contain the string
– Thomas G
Jan 2 at 14:20
I just tried to do the same with LastUserConfirmedResolutionSizeX, and it didn't work, heres the code: If System.IO.File.Exists(strFile) Then Dim arrLines() As String = IO.File.ReadAllLines(strFile) For i As Integer = 0 To arrLines.Length - 1 If Strings.Left(arrLines(i), 16) = "ResolutionSizeX=" Then arrLines(i) = "ResolutionSizeX=1920" ElseIf Strings.Left(arrLines(i), 16) = "LastUserConfirmedResolutionSizeX=" Then arrLines(i) = "LastUserConfirmedResolutionSizeX=1920" End If Next System.IO.File.WriteAllLines(strFile, arrLines) 'SAVE End If
– Narpzy
Jan 2 at 14:28
Remove theFile.Exists()
check. It's almost always counter-productive, and usually makes things slower; you're normally better off just handling the exception.
– Joel Coehoorn
Jan 2 at 14:35
If you want to make it work with other variables, you have to adapt the 16 in the Left instruction. 16 is the number of chars in your string, including the = at the end
– Thomas G
Jan 2 at 14:36
It does the trick, but if I have something named LastUserConfirmedResolutionSizeX it changes that too to ResolutionSizeX.
– Narpzy
Jan 2 at 14:14
It does the trick, but if I have something named LastUserConfirmedResolutionSizeX it changes that too to ResolutionSizeX.
– Narpzy
Jan 2 at 14:14
@Narpzy adapted the code so it checks if the 16 first chars of the line are ResolutionSizeX=, and not simply contain the string
– Thomas G
Jan 2 at 14:20
@Narpzy adapted the code so it checks if the 16 first chars of the line are ResolutionSizeX=, and not simply contain the string
– Thomas G
Jan 2 at 14:20
I just tried to do the same with LastUserConfirmedResolutionSizeX, and it didn't work, heres the code: If System.IO.File.Exists(strFile) Then Dim arrLines() As String = IO.File.ReadAllLines(strFile) For i As Integer = 0 To arrLines.Length - 1 If Strings.Left(arrLines(i), 16) = "ResolutionSizeX=" Then arrLines(i) = "ResolutionSizeX=1920" ElseIf Strings.Left(arrLines(i), 16) = "LastUserConfirmedResolutionSizeX=" Then arrLines(i) = "LastUserConfirmedResolutionSizeX=1920" End If Next System.IO.File.WriteAllLines(strFile, arrLines) 'SAVE End If
– Narpzy
Jan 2 at 14:28
I just tried to do the same with LastUserConfirmedResolutionSizeX, and it didn't work, heres the code: If System.IO.File.Exists(strFile) Then Dim arrLines() As String = IO.File.ReadAllLines(strFile) For i As Integer = 0 To arrLines.Length - 1 If Strings.Left(arrLines(i), 16) = "ResolutionSizeX=" Then arrLines(i) = "ResolutionSizeX=1920" ElseIf Strings.Left(arrLines(i), 16) = "LastUserConfirmedResolutionSizeX=" Then arrLines(i) = "LastUserConfirmedResolutionSizeX=1920" End If Next System.IO.File.WriteAllLines(strFile, arrLines) 'SAVE End If
– Narpzy
Jan 2 at 14:28
Remove the
File.Exists()
check. It's almost always counter-productive, and usually makes things slower; you're normally better off just handling the exception.– Joel Coehoorn
Jan 2 at 14:35
Remove the
File.Exists()
check. It's almost always counter-productive, and usually makes things slower; you're normally better off just handling the exception.– Joel Coehoorn
Jan 2 at 14:35
If you want to make it work with other variables, you have to adapt the 16 in the Left instruction. 16 is the number of chars in your string, including the = at the end
– Thomas G
Jan 2 at 14:36
If you want to make it work with other variables, you have to adapt the 16 in the Left instruction. 16 is the number of chars in your string, including the = at the end
– Thomas G
Jan 2 at 14:36
|
show 2 more comments
1
What's your question? Is something not working as expected? What isn't working? Which step along the way is the first to fail? (Hint: Separate your operations into individual lines of code to observe them one at a time while debugging.) What data is in your file? Please specify the problem.
– David
Jan 2 at 13:09
I wanted every single number that is possible in it to become 1920, if it is like 1628 or 980 or 16 or 12034 you understand?
– Narpzy
Jan 2 at 13:14
what do you mean about "Can you do it in a text editor which supports regular expressions?"
– Narpzy
Jan 2 at 13:25
check this out to edit INI files - stackoverflow.com/questions/217902/reading-writing-an-ini-file
– Ctznkane525
Jan 2 at 13:33
Im doing this in visual basic. When I tried it, it didn't work.
– Narpzy
Jan 2 at 13:46