<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="http://www.bytemycode.com/rssformat.xsl"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>byteMyCode: Snippet Revisions</title>
		<link>http://www.bytemycode.com</link>
		<description>Revisions for this snippet.</description>
		<pubDate>Fri, 05 Sep 2008 06:41:16 +0000</pubDate>
		<copyright>1998-2008 </copyright>
		<language>en-us</language>
		<image>
		      <link>http://www.bytemycode.com</link>
		      <url>http://www.bytemycode.com/img/rss_title.gif</url>
		      <title>byteMyCode</title>
		</image>

	
	<item>
		<title>trim, ltrim, and rtrim in C 1</title>
		<link>http://www.bytemycode.com/snippets/snippet/399/1/</link>
		<comments>http://www.bytemycode.com/snippets/snippet/399/comments/</comments>
		<pubDate>Tue, 26 Sep 2006 13:13:39 +0000</pubDate>
		<dc:creator>sehrgut</dc:creator>
		<category>C, ltrim, Parse, rtrim, String, trim</category>
		<guid isPermaLink="false">http://www.bytemycode.com/snippets/snippet/399/</guid>
		<description>
			<![CDATA[
				<p>The <i>modus operandi</i> for this is similar to that taken by PHP's implementation of such functions. It's comparitively memory-intensive, but is much faster than running a whole bunch of tests.<br /><br />Basically, you set a mask -- an array of 256 null bytes -- and set those that correspond to characters you wish to trim. Then, rather than having to test if a character is in the set of characters to trim(O(n), or linear time on *ws), you just test once (O(1), or unit time) to see if the byte in question is set.<br /><br />And of course, to trim(), you just wrap trim() around both ltrim() and rtrim().<br /><br />One point of caution: these functions trim in place, so copy strings before trimming them. (Of course, if you usually want access to both pre- and post-trimmed strings, you could always make these malloc() a new string and return a pointer to it . . . )</p>
			]]>
		</description>
	</item>

	
	</channel>
</rss>