<?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: Snippets for ltrim</title>
		<link>http://www.bytemycode.com</link>
		<description>Snippets for this tag.</description>
		<pubDate>Thu, 04 Dec 2008 13:56:21 +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</title>
	<link>http://www.bytemycode.com/snippets/snippet/399/</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[

			<img src="http://www.bytemycode.com/img/icon_calendar.gif" align="middle" class="icon" alt="Date Submitted" /> Tue. Sep. 26th, 2006  1:13 PM			<br />
			<img src="http://www.bytemycode.com/img/icon_revision.gif" align="middle" class="icon" alt="Revision" /> <a href="http://www.bytemycode.com/snippets/snippet/399/revisions/">1</a>
			<br />
			<img src="http://www.bytemycode.com/img/rank_scripter.gif" align="middle" class="icon" alt="Scripter" /> <a href="http://www.bytemycode.com/members/member/sehrgut/" title="Scripter">sehrgut</a>
			<br />
			<img src="http://www.bytemycode.com/img/icon_tag.gif" align="middle" class="icon" alt="Tags" /> <a href="http://www.bytemycode.com/tags/tag/C">C</a>&nbsp;|&nbsp;<a href="http://www.bytemycode.com/tags/tag/ltrim">ltrim</a>&nbsp;|&nbsp;<a href="http://www.bytemycode.com/tags/tag/Parse">Parse</a>&nbsp;|&nbsp;<a href="http://www.bytemycode.com/tags/tag/rtrim">rtrim</a>&nbsp;|&nbsp;<a href="http://www.bytemycode.com/tags/tag/String">String</a>&nbsp;|&nbsp;<a href="http://www.bytemycode.com/tags/tag/trim">trim</a>			<br />
			<img src="http://www.bytemycode.com/img/icon_comments.gif" align="middle" class="icon" alt="Comments" /> <a href="http://www.bytemycode.com/snippets/snippet/399/comments/">1 comments</a>
			<br />
			<img src="http://www.bytemycode.com/img/icon_ranking.gif" align="middle" class="icon" alt="Ranking" /> 7
			<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>