<?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/"
	>

<channel>
	<title>Joe Lanman &#187; strings</title>
	<atom:link href="http://www.joelanman.com/by_tag/strings/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.joelanman.com</link>
	<description>Web design and development when not playing computer games</description>
	<lastBuildDate>Sat, 18 Dec 2010 19:10:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Python-style startswith and endswith string functions in Javascript</title>
		<link>http://www.joelanman.com/2008/07/python-style-startswith-and-endswith-string-functions-in-javascript/</link>
		<comments>http://www.joelanman.com/2008/07/python-style-startswith-and-endswith-string-functions-in-javascript/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 17:06:49 +0000</pubDate>
		<dc:creator>Joe Lanman</dc:creator>
				<category><![CDATA[Front-end]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[strings]]></category>

		<guid isPermaLink="false">http://www.joelanman.com/?p=4</guid>
		<description><![CDATA[The Python language has useful string methods to search for prefixes and suffixes: my_string.startswith('pre') The same thing can be achieved in Javascript using the rather powerful search and replace methods. These methods can either accept strings or regular expressions.  To search for a plain string, use quote marks, for example: my_string.search('tom'); This will return the [...]]]></description>
			<content:encoded><![CDATA[<p>The Python language has useful string methods to search for prefixes and suffixes:</p>
<pre><code>
my_string.startswith('pre')</code></pre>
<p>The same thing can be achieved in Javascript using the rather powerful search and replace methods.</p>
<p><span id="more-4"></span></p>
<p>These methods can either accept strings or regular expressions.  To search for a plain string, use quote marks, for example:</p>
<pre><code>
my_string.search('tom');</code></pre>
<p>This will return the index of the first occurence of &#8216;tom&#8217; in my_string.</p>
<p>To search for a regular expression, use slashes. Regular expressions use special characters to search for particular patterns in strings &#8211; we&#8217;ll just be using the &#8216;starts with&#8217; (^)  and &#8216;ends with&#8217; ($) characters. Therefore, our Python-style startswith and endswith tests looks like this:</p>
<pre><code>
my_string.search(/^prefix/) ;

my_string.search(/suffix$/);</code></pre>
<p><strong>Note from <a href="http://x13n.com/alex" class="aga aga_1">Alex Macmillan</a></strong> (honorary proof reader)</p>
<p>While the Python functions return a boolean value depending on the match, the Javascript versions return the index of the matched string. If they are not found, the return value will be -1, not false.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joelanman.com/2008/07/python-style-startswith-and-endswith-string-functions-in-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.375 seconds -->

