Jump to content
Sign in to follow this  
Dgameman1

Add Variable inside String

Recommended Posts

Dgameman1

Let's say this is the code I have

$CurrentMatchUsername = "Dgameman1"
$picklineText = "#FirstName#!! Hey, hi!"
FileWrite("C:\Users\Dgameman1\Desktop\test.txt", $picklineText)

How can I make it so that the file on my desktop named 'test.txt' will replace every instance of #FirstName# with `$CurrentMatchUsername`.

The end result is for the text.txt file to have the sentence, Dgameman1!! Hey, hi!

Share this post


Link to post
Share on other sites
markyrocks
$sLeft=stringleft ($picklineText,10)
If $sLeft="#FirstName#" then 
Filewrite ($file, $CurrentMatchUsername & "!!Hey, hi!")
EndIf

Something like that.  

Edited by markyrocks
...

Share this post


Link to post
Share on other sites
Exit

Use the Opt("ExpandVarStrings", 1) function to replace variables.

Opt("ExpandVarStrings", 1) ;0=don't expand, 1=do expand

$CurrentMatchUsername = "Dgameman1"
$CurrentMatchUsername = @UserName  ; just to test with own osername
$picklineText = "$CurrentMatchUsername$!! Hey, hi!"
FileWrite("C:\Users\$CurrentMatchUsername$\Desktop\test.txt", $picklineText)

 

  • Like 1

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.