This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ETHANATOR360's profile picture

combining strings

Started by ETHANATOR360, 25 November 2012 - 07:39 AM
ETHANATOR360 #1
Posted 25 November 2012 - 08:39 AM
im scripting something that creates a file but i want to add a file extension how do i add ".nfp" to a string variable
Goof #2
Posted 25 November 2012 - 08:47 AM
You could just use :

Sfile = fs.open(input..".nfp", "w")

thats my way?
ETHANATOR360 #3
Posted 25 November 2012 - 09:01 AM
what about:
local filename…".nfp" = read()
dissy #4
Posted 25 November 2012 - 09:12 AM
The string.format command can output the combination of two strings, variables, or one of each.
It is similar to printf in C. %s represents string, and two of them expects two arguments each being a string.

Example:

a="one"
b=string.format("%s%s", a, ".two")

b should be "one.two"
MysticT #5
Posted 25 November 2012 - 09:44 AM
If you want to use the user input, it should be like this:

local filename = read()
filename = filename..".nfp"
KaoS #6
Posted 25 November 2012 - 11:09 PM
you can put it onto one line too. pretty much what mystic said
local fName=read()..'.nfp'