[Help]Search a file for item

Posts 16 of 6 · Page 1 of 1
[Help]Search a file for item
Hello i want to search config_mp.cfg file from mw2 and find this piece:r_fullscreen "0" and able to save the file again with r_fullscreen "1" i know the part of saving and loading file etc. But how can i search a file for that item?
[php]Using sRead as new io.streamreader("path")
Dim full as string = sRead.ReadToEnd

full = full.replace("old", "new")
end using[/php]

[php]Using sWrite as new io.streamwriter("path")
sWrite.write(full)
end using
[/php]

[php]If full.contains("bla") then

end if[/php]
i coudn't get it what i understood u want to search for a file named with config_mp.cgf
in mw2 folder and find in it's text r_fullscreen "0" and replace it with r_fullscreen "1" then save it is't right?
if so
Dim S As String = Nothing
Dim Mw2Config_mpcfgLocation As String = Nothing 'replace nothing with the location of config_mp.cfg
S = My.Computer.FileSystem.ReadAllText(Mw2Config_mpcfg Location)
S = S.Replace("0", "1")
System.IO.File.WriteAllText(Mw2Config_mpcfgLocatio n, S)
this get all text of config_***.cgf to s declared string then it replaces 0 in it with one
if i'm wrong please tell me what you want
That just replaces every 0 to 1, you trying to kill someone?

Replace filePath with the correct file path.

[php] Dim filePath As String = Nothing
Dim contents As String = IO.File.ReadAllText(filePath)
Dim write As String
Dim RegPattern As New System.Text.RegularExpressions.Regex("r_fullscreen ""[0-9]+""")
write = RegPattern.Replace(contents.ToString, "r_fullscreen ""0""")
IO.File.WriteAllText(filePath, write)[/php]
Quote Originally Posted by master131 View Post
That just replaces every 0 to 1, you trying to kill someone?
oh , never thought of that
Code:
Dim S As String = Nothing
Dim Mw2Config_mpcfgLocation As String = Nothing 'replace nothing with the location of config_mp.cfg
S = My.Computer.FileSystem.ReadAllText(Mw2Config_mpcfg Location)
S = S.Replace("r_fullscreen ""0""", "r_fullscreen ""1""")
System.IO.File.WriteAllText(Mw2Config_mpcfgLocatio n, S)
this should work
2 Lines of disgusting code for j00 (could be shortened to one but oh well

[php]
Dim loc As String = "C:\Test\Test.txt"
IO.File.WriteAllText(loc, IO.File.ReadAllText(loc).Replace("r_fullscreen 0", "r_fullscreen 1"))
[/php]

Oh yeah.
Posts 16 of 6 · Page 1 of 1
This thread is closed for replies.

Tags for this Thread

None

Need help?