Sign in to follow this  
Followers 0
Dgameman1

Add Variable inside String

4 posts in this topic

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



$picklineText = StringReplace($picklineText, "#FirstName#", $CurrentMatchUsername)

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

$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

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)

 

1 person likes this

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  
Followers 0