Vb Script how to do a replace and also add text on the same line


Can someone advise on my code please? I already manipulate a line of text by adding 4 characters, easy so far however im having a problem then trying to do a replace of 8 characters at the end of the same line.

Hes the code i already have that adds 4 characters to the line.

Source text line, note 1014 note added yet:

-   LDE1CM108ASN850FD  F1234   DHGYTH   6234652246973101HNPAAAAU

'write line with '1014' added 8 spaces in
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1014" & Right(HeaderText_FirstLine, Len(HeaderText_FirstLine) - 8)

result, note 1014 is now added to the line, all good so far!:
-   LDE11014CM108ASN850FD  F1234   DHGYTH   6234652246973101HNPAAAAU

Now i want to change the last 8 characters of the same line(HNPAAAAU) with NNNTUIPP

Not sure how to do it with it giving me errors

I thought it would be as easy as
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1014" & Right(HeaderText_FirstLine, Len(HeaderText_FirstLine) - 8), replace (replacetxt, "HNPAAAAU","NNNTUIPP")

But this adds another line, arhh!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I made two changes to your last line.
1. instead of cutting off only 8 characters from the end, lets cut off the first 8 and last 8 using Mid.
2. Just append the new string to the end
w1.WriteLine Left(HeaderText_FirstLine, 8) & "1014" & Mid(HeaderText_FirstLine, 9, Len(HeaderText_FirstLine) - 16) &"NNNTUIPP"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wilko1000Author Commented:
Excellent works thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.