<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>Man With Code &#187; strings</title>
	<atom:link href="http://manwithcode.com/tag/strings/feed/" rel="self" type="application/rss+xml" />
	<link>http://manwithcode.com</link>
	<description>Teaching You, One Tutorial at a Time</description>
	<lastBuildDate>Wed, 11 Aug 2010 02:52:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Programming With Ruby Episode 6, Strings</title>
		<link>http://manwithcode.com/101/programming-with-ruby-episode-6-strings/</link>
		<comments>http://manwithcode.com/101/programming-with-ruby-episode-6-strings/#comments</comments>
		<pubDate>Thu, 21 May 2009 09:17:42 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Ruby Programming]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[strings]]></category>

		<guid isPermaLink="false">http://manwithcode.com/?p=101</guid>
		<description><![CDATA[Covered in this episode: String Literals String Expressions String Methods Regular Expressions Getting User Input (gets) Transcript: Hello Everyone and Welcome to Programming With Ruby Episode 6, Strings. I&#8217;m Tyler, your presenter. This is brought to you by manwithcode.com In this episode I will be telling you what string literals are. I will show you [...]]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/1ot2Wlsgsog&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/1ot2Wlsgsog&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><strong>Covered in this episode:</strong></p>
<ul>
<li>String Literals</li>
<li>String Expressions</li>
<li>String Methods</li>
<li>Regular Expressions</li>
<li>Getting User Input (gets)<strong> </strong><strong></strong></li>
</ul>
<p><strong>Transcript:</strong></p>
<p>Hello Everyone and Welcome to Programming With Ruby Episode 6,<br />
Strings. I&#8217;m Tyler, your presenter. This is brought to you by<br />
manwithcode.com</p>
<p>In this episode I will be telling you what string literals are. I will<br />
show you expressions you can use with strings, which are similar but<br />
still different than expressions with numbers. I will show you useful<br />
methods strings have. I will show you how to use regular<br />
expressions. Finally I will teach you how to get input from the<br />
user.</p>
<p>On to the Code!</p>
<p><strong>String Literals</strong></p>
<p>According to wikipedia, string literals are the representation of a<br />
string value within the source code of a computer program. For<br />
example:</p>
<pre class="brush: ruby;">
puts &quot;Hello World&quot; # Hello World is the string literal
</pre>
<p><strong>String Expressons</strong></p>
<p>The only string expressions are the plus and multiplication sign. The<br />
plus sign connects strings together, the multiplication sign repeats a<br />
string a certain number of times.<br />
Let me show you how it works:</p>
<pre class="brush: ruby;">
&quot;Hello &quot; + &quot;World!&quot; #=&gt; &quot;Hello World!&quot;
&quot;Hello &quot; * 3 #=&gt; &quot;Hello Hello Hello&quot;
</pre>
<p><strong>String Methods</strong></p>
<p>Here are some useful String methods:<br />
<em>empty?</em> tells you if you are dealing with an empty string<br />
<em>length</em> tells you how long a string is<br />
<em>each_char</em> lets you iterate over each character<br />
<em>capitalize</em> capitalizes the first character<br />
<em>upcase</em> makes all characters upper case<br />
<em>downcase</em> makes all characters lower case</p>
<p><strong>Regular Expressions</strong></p>
<p>Regular expressions are a way to match elements in other strings. It<br />
is easier to show you than to describe to you, so here we go!</p>
<p>The simplest is substitution:</p>
<pre class="brush: ruby;">
&quot;Hello World&quot;.sub(&quot;Hello&quot;, &quot;Goodbye&quot;)
#=&gt; &quot;Goodbye World&quot;
</pre>
<p>But if you have more than one hello:</p>
<pre class="brush: ruby;">
&quot;Hello Hello Hello&quot;.sub(&quot;Hello&quot;, &quot;Goodbye&quot;)
#=&gt; &quot;Goodbye Hello Hello&quot;
</pre>
<p>This happens because the sub method only replaces the first occurrence<br />
of &#8220;Hello&#8221;. The gsub method fixes this:</p>
<pre class="brush: ruby;">
&quot;Hello Hello Hello&quot;.gsub(&quot;Hello&quot;, &quot;Goodbye&quot;)
#=&gt; &quot;Goodbye Goodbye Goodbye&quot;
</pre>
<p>What if you want to manipulate parts of a string using regular<br />
expressions. The scan method is what you want!</p>
<pre class="brush: ruby;">
# /n means new line
&quot;Who are you&quot;.scan(/../) { |x| puts x }
#=&gt; Wh\no \nar\ne \nyo
# With no whitespace:
&quot;Who are you&quot;.scan(/\w\w/) { |x| puts x }
#=&gt; Wh/nar/nyo
</pre>
<p>Regular Expressions are a vast topic that I can&#8217;t completely cover<br />
here, so do a Google search to find out more.</p>
<p><strong>Getting User Input</strong></p>
<p>You can get user input with the &#8220;gets&#8221; method:</p>
<pre class="brush: ruby;">
a = gets
# The user inputs: I like pie
puts a #=&gt; &quot;I like pie&quot;
</pre>
<p>That wraps it up for todays episode.</p>
<p>Don&#8217;t forget to donate, the link is to the right of this video</p>
<p>If you have any questions or comments, leave a comment on this page or<br />
email me at tyler@manwithcode.com</p>
<p>Bye!</p>
]]></content:encoded>
			<wfw:commentRss>http://manwithcode.com/101/programming-with-ruby-episode-6-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[Ruby Programming]]></series:name>
	</item>
	</channel>
</rss>
