Rails 2.3.5
I need a temp work around for a script that only has 1 possible styling. Is there a simple way to loop through a string and add line breaks? Like at every 80th character insert a '\n'? (really looping through a record set and doing this to a text field).
Thanks!
Here is another approach:
"hello".scan(/.{1}/).join("\n")
Not sure this is the best approach.. but you could use each_slice here. Maybe something like:
"SOME AWESOME STRING".chars.each_slice(80).map(&:join).join('\n')
Related
I'm trying, to wrap my head around Touchosc and script based on LUA 5.1.
I have a number of labels, called song0, song1, song2, and so on. I'm trying to set different values in these, using
local text = 'Smoke On The Water'
for i = 1, 2 do
self.children.pager1.children.main.children.song[i].values.text = text
end
but that gives me an error.
:-) I do need help.
Finn
Since you haven't provided the actual error, it's difficult to say what the problem is, but if I have to venture a guess, then try replacing ...children.song[i].values... with ...children["song"..i].values.... Since there is no table song, you just need to generate dynamic field names.
I've tried several guides, but i haven't really found that any of them fit my purpose.
The problem seems simple enough, i want to create a dynamic link based on a variable.
I've tried inserting a Hyperlink with temp text and link, replacing the text within the "" brackets, with a MergeField corresponding to the variable.
Whenever i test it, the variable does not register. The syntax is as follows :
{ HYPERLINK "www.staticurl/{MergeField varurl}" }
Does anyone have any suggestions on why this variable does not register?
Thanks in advance!
i would like to know how i could cut and mix strings, im making a player fusion script for my game, but i dont know how i can make their name be togheter, like, if player 1 name is LordNoob and player 2 name is Keyboard then it would mix their names to one like Lordoard or KeyNoob something like that.
Ive searching a few things on the roblox wiki but i didnt found nothing, i saw string patterns but i dont know if it would help me.
If anyone could tell me what i could do it would be a cool help. thank you.
I've tried making a function for you which works okay, having the flaws that Paul mentioned
function mixStrings(string1,string2)
return string.upper(string.sub(string1,1,1)) .. string.lower( string.sub( string.sub(string1,1,math.floor(string.len(string1)/2)) ,2,string.len(string.sub(string1,1,math.floor(string.len(string1)/2)))) .. string.sub(string2,math.ceil(string.len(string2)/2),string.len(string2)) )
end
print(mixStrings("Keyboard","Calculator"))
print(mixStrings("Narwhal","Shark"))
print(mixStrings("America","Europe"))
print(mixStrings("Spoon","Fork"))
Running the above script resulted in the following when I tested it:
Keybulator
Narark
Amerope
Spork
(Btw the function will always make a string with a capitalized first letter and the rest will be lowercase, so it probably won't be useful if you're aiming to make something like KeyNoob)
I ran into some problems with my code and I don't know how to fix it. So my problem:
On a View of my application, there is a filepath displayed like this:
/resume/attachment/12/yaml_error_complete.yml
But I only want the filename as Output, means:
yaml_error_complete.yml
How can i achieve this? I tried with several options like string.slice! etc, but it doesn't work, since the number after "attachment" is increased by 1 for every single upload. At beginning I thought about to simply remove 2 chars, don't matter what they are. But then i ran into another problem that happens when the 100 file is uploaded. In this case i would have to remove 3 chars instead of 2, and i'm again at the beginning of my problem.
May someone of you can help me?
Thanks a lot!
I assume that you need to retrieve the file of a path.
for ex if your file name is "/resume/attachment/12/yaml_error_complete.yml"
Then try this one
"/resume/attachment/12/yaml_error_complete.yml".split('/').last
If I understand your question right, then, maybe it should help you:
a = "/resume/attachment/12/yaml_error_complete.yml"
a.split('/').last
#=> "yaml_error_complete.yml"
In addition to the sulution with split('/') you could do the following
File.basename("/resume/attachment/12/yaml_error_complete.yml")
I have such integer values like yearmonth, but i wont to see month-year, how I can do this in rails view?
for example
197903 198812
must be viewed as
03-1979 12-1988
try this
"#{197903.to_s[0...4]}-#{197903.to_s[4...6]}"
There may be a more elegant way of doing this if you can convert it to a date object first.