
Originally Posted by
relentlesstech
The file is slightly larger - It is a CFG file that holds all the data to 'create' a vehicle in one of my games ...
That will make things a bit easier then if we can use the System.IO.File methods.
I came up with this:
vbnet Code:
Dim fileText As String = File.ReadAllText("F:\file.txt")
Dim attchRegion As String = String.Join(Environment.NewLine, _
Regex.Matches(fileText, "attach\t\t0x\d{8}\b 1 ; \d{2}\b") _
.Cast(Of Match)().Select(Function(m) m.Value))
fileText = fileText.Replace(attchRegion, "NEW REPLACEMENT VALUE")
TextBox1.Text = fileText
And from the input file I had:
# Vehicle importer wizard generated vehicle configuration file #
center -0.005 0.670 0.019
material 0x00000000 0x0005000B 0x0005000B
compound
compound
chassis
body 0.0 0.0 0.0 0.0 0.0 0.0 0.001 box 0.001 0.001 0.001
noclick
bone
body 0.001 -0.227 -1.833 0.000 0.000 0.000 10.000 cars\racers\Axis_V3\meshes\_phys_chassis_F.scx ;0x0000000C
# FL wheel #
type 10.000 sphere 0.44
spring 0.290 0.100 0.050
wheel -0.785 -0.544 -1.305 0.000 0.000 0.000 1.000 1.000 1.000 0.000
wheelbones
slot 0.000 0.000 0.000 0.000 0.000 0.000 101 ; FL wheel
attach 0x00040100 1 ; 14
attach 0x00040101 1 ; 15
attach 0x00040102 1 ; 16
attach 0x00040103 1 ; 17
attach 0x00040104 1 ; 18
attach 0x00040105 1 ; 19
attach 0x00040106 1 ; 20
attach 0x00040107 1 ; 21
slottype 101
slotdmgmode 0x00000005
slot 0.000 0.000 0.000 0.000 0.000 0.000 201 ; FL suspension arm
slottype 301
slotdmgmode 0x00000006
It gave me:
# Vehicle importer wizard generated vehicle configuration file #
center -0.005 0.670 0.019
material 0x00000000 0x0005000B 0x0005000B
compound
compound
chassis
body 0.0 0.0 0.0 0.0 0.0 0.0 0.001 box 0.001 0.001 0.001
noclick
bone
body 0.001 -0.227 -1.833 0.000 0.000 0.000 10.000 cars\racers\Axis_V3\meshes\_phys_chassis_F.scx ;0x0000000C
# FL wheel #
type 10.000 sphere 0.44
spring 0.290 0.100 0.050
wheel -0.785 -0.544 -1.305 0.000 0.000 0.000 1.000 1.000 1.000 0.000
wheelbones
slot 0.000 0.000 0.000 0.000 0.000 0.000 101 ; FL wheel
NEW REPLACEMENT VALUE
slottype 101
slotdmgmode 0x00000005
slot 0.000 0.000 0.000 0.000 0.000 0.000 201 ; FL suspension arm
slottype 301
slotdmgmode 0x00000006
I'm assuming the replacement value will be another bunch of "attach 0x00040104 1 ; 18" similar values. So as long as you String.Join() these values with a newline, then when it comes time to use my Regex LINQ, then it will match every one of those lines in the textfile of those attach lines.
Note: For my regex, I assumed that the 1 in each of those lines will never be a different number, if it is, I can just change my regex around a bit.
If it's only going to always be one digit:
Code:
attach\t\t0x\d{8}\b [0-9] ; \d{2}\b