Difference between revisions of "Talk:S2 Cookbook: Strings"

From Dreamwidth Notes
Jump to: navigation, search
(Created page with 'I think the "Repeating a string" example might be kind of confusing because it talks about "replacing" one string with another, but no actual replacement is done, and string repl…')
 
Line 19: Line 19:
  
 
--[[User:Murklins|Murklins]] 05:53, 2 July 2010 (UTC)
 
--[[User:Murklins|Murklins]] 05:53, 2 July 2010 (UTC)
 +
 +
: Oh, and while I'm here talking to myself, might be a good idea to add a really basic "Concatenating two strings together" section near the beginning of this category, just to illustrate the use of the + sign in the context of strings. --[[User:Murklins|Murklins]] 06:30, 2 July 2010 (UTC)

Revision as of 06:30, 2 July 2010

I think the "Repeating a string" example might be kind of confusing because it talks about "replacing" one string with another, but no actual replacement is done, and string replacement is actually covered by the next code sample. I'm thinking something more like this:

var string sentence = "I am a quick brown fox.";
var int length = $sentence->length();
var string underline = "-";
 
# Print out the sentence.
"""<p style="font-family: courier;">$sentence""";
 
# Underline the sentence using the $underline string.
"<br />" + $underline->repeat( $length ) + "</p>";

Will print out:

I am a quick brown fox.
-----------------------

--Murklins 05:53, 2 July 2010 (UTC)

Oh, and while I'm here talking to myself, might be a good idea to add a really basic "Concatenating two strings together" section near the beginning of this category, just to illustrate the use of the + sign in the context of strings. --Murklins 06:30, 2 July 2010 (UTC)