Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Add text to unknown string

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,64136
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Add text to unknown string
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Add text to unknown string - 9/9/2008 1:55:06 AM   
  ingmar

 

Posts: 7
Score: 0
Joined: 9/9/2008
Status: offline
Hi, nice and interesting forum which has helped me already a lot.
But there is something I don't seem to find...

I want to add text to a string in a textfile.
So let's say I receive a file called "text.txt", containing a string which always starts with "message :"
The following words are variable, so I don't really know the message

SO, Message: Hello how are you doing?

I would like to add a Word to that message. The result should be something like this: "Message : Hello how are you doing? by Ingmar"

I found the replace function, but I don't know how to use it with a variable string.
Can anybody help me, by giving some basic code are some terms I could search for?

Tnx in advance!
 
 
Post #: 1
 
 RE: Add text to unknown string - 9/9/2008 2:38:41 AM   
  ginolard


Posts: 1066
Score: 21
Joined: 8/10/2005
Status: offline
You don't need the Replace function.  If it's always just one line then read the file into a variable and append whatever you want to the end of it using the ampersand operator.

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to ingmar)
 
 
Post #: 2
 
 RE: Add text to unknown string - 9/9/2008 5:00:27 AM   
  ingmar

 

Posts: 7
Score: 0
Joined: 9/9/2008
Status: offline
Ok, tnx. But how can I read in just thát line that starts with the word "Message" ? The text file contains other data as well?
So there's more than 1 line.

Edit: I just found this code:


      

But I don't know how to store the whole message in a variable and then use it in a  ".WriteLine" function.
When I try this:
       it gives me a file with  'Message = ...' and it should be the whole message

< Message edited by ingmar -- 9/9/2008 5:57:06 AM >

(in reply to ginolard)
 
 
Post #: 3
 
 RE: Add text to unknown string - 9/9/2008 7:31:14 AM   
  ehvbs

 

Posts: 2202
Score: 50
Joined: 6/22/2005
From: Germany
Status: online
Hi ingmar,

Have a look at


      

output:


      

and consider whether .ReadAll, a RegExp, and rewriting the file could be a way to
solve your problem.

Good luck!

ehvbs

(in reply to ingmar)
 
 
Post #: 4
 
 RE: Add text to unknown string - 9/9/2008 7:16:43 PM   
  ingmar

 

Posts: 7
Score: 0
Joined: 9/9/2008
Status: offline
Ok thank you!

< Message edited by ingmar -- 9/9/2008 7:30:47 PM >

(in reply to ehvbs)
 
 
Post #: 5
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Add text to unknown string Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts