Jump to content




combining strings


  • You cannot reply to this topic
5 replies to this topic

#1 ETHANATOR360

  • Members
  • 423 posts
  • Locationyour hardrive

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

#2 Goof

  • Members
  • 751 posts

Posted 25 November 2012 - 08:47 AM

You could just use :

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

thats my way?

#3 ETHANATOR360

  • Members
  • 423 posts
  • Locationyour hardrive

Posted 25 November 2012 - 09:01 AM

what about:
local filename...".nfp" = read()

#4 dissy

  • Members
  • 181 posts

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"

#5 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

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"


#6 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 25 November 2012 - 11:09 PM

you can put it onto one line too. pretty much what mystic said
local fName=read()..'.nfp'






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users