<?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>eXclusiveMinds &#187; Sentence Reverse</title>
	<atom:link href="http://eXclusiveMinds.com/tag/sentence-reverse/feed/" rel="self" type="application/rss+xml" />
	<link>http://eXclusiveMinds.com</link>
	<description>eXclusive resource for programmers, developers and designers</description>
	<lastBuildDate>Sat, 13 Mar 2010 23:28:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Program to reverse sentence word by word using C#</title>
		<link>http://eXclusiveMinds.com/2009/12/09/program-to-reverse-sentence-word-by-word-using-c/</link>
		<comments>http://eXclusiveMinds.com/2009/12/09/program-to-reverse-sentence-word-by-word-using-c/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 18:40:21 +0000</pubDate>
		<dc:creator>eXclusiveMinds</dc:creator>
				<category><![CDATA[Inverview Tips]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Sentence Reverse]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[String Reverse]]></category>

		<guid isPermaLink="false">http://eXclusiveMinds.com/2009/12/09/program-to-reverse-word-by-word-using-c/</guid>
		<description><![CDATA[This example shows how can we reverse a sentence word by word. For example; If we have string &#8220;This is an eXclusiveMinds article&#8221; output should be &#8220;article eXclusiveMinds an is This&#8221;. For this we have two methods ReverseWordByWord and Reverse (this is helper method to reverse string character by character).
This is also one of the [...]]]></description>
			<content:encoded><![CDATA[<p>This example shows how can we reverse a sentence word by word. For example; If we have string &#8220;This is an eXclusiveMinds article&#8221; output should be &#8220;article eXclusiveMinds an is This&#8221;. For this we have two methods ReverseWordByWord and Reverse (this is helper method to reverse string character by character).<br />
This is also one of the most frequently asked interview question in Microsoft, Google and Amazon for position of Software Design/Development Engineer (or Test).<br />
<span id="more-347"></span></p>

<div class="wp_syntax"><table><tr><td><div class="code"><pre class="csharp" style="font-family:Consolas; monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Function to reverse sentence word by word</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;sentence&quot;&gt;string (sentence)&lt;/param&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;returns&gt;reversed string by word&lt;/returns&gt;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> ReverseWordByWord<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> sentence<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #FF0000;">char</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> str <span style="color: #008000;">=</span> sentence.<span style="color: #0000FF;">ToCharArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	str <span style="color: #008000;">=</span> Reverse<span style="color: #000000;">&#40;</span>str, <span style="color: #FF0000;">0</span>, str.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #FF0000;">int</span> start <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>, end <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> str.<span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>str<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> <span style="color: #008000;">==</span> <span style="color: #666666;">' '</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			end <span style="color: #008000;">=</span> i <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
			str <span style="color: #008000;">=</span> Reverse<span style="color: #000000;">&#40;</span>str, start, end<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			start <span style="color: #008000;">=</span> i <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">//For Last word</span>
	end <span style="color: #008000;">=</span> str.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
	str <span style="color: #008000;">=</span> Reverse<span style="color: #000000;">&#40;</span>str, start, end<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#40;</span>str<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></td></tr></table></div>

<p>This method is helper function which will reverse a string character by character.</p>

<div class="wp_syntax"><table><tr><td><div class="code"><pre class="csharp" style="font-family:Consolas; monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Helper method to reverse string character by character.</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;str&quot;&gt;string to be reversed&lt;/param&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;start&quot;&gt;start index&lt;/param&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;end&quot;&gt;end index&lt;/param&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;returns&gt;reversed string&lt;/returns&gt;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">char</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> Reverse<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">char</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> str, <span style="color: #FF0000;">int</span> start, <span style="color: #FF0000;">int</span> end<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span>end <span style="color: #008000;">&gt;</span> start<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		str<span style="color: #000000;">&#91;</span>start<span style="color: #000000;">&#93;</span> <span style="color: #008000;">^=</span> str<span style="color: #000000;">&#91;</span>end<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
		str<span style="color: #000000;">&#91;</span>end<span style="color: #000000;">&#93;</span> <span style="color: #008000;">^=</span> str<span style="color: #000000;">&#91;</span>start<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
		str<span style="color: #000000;">&#91;</span>start<span style="color: #000000;">&#93;</span> <span style="color: #008000;">^=</span> str<span style="color: #000000;">&#91;</span>end<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
		end<span style="color: #008000;">--;</span>
		start<span style="color: #008000;">++;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0600FF;">return</span> str<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></td></tr></table></div>

<p>Testing This Method:</p>

<div class="wp_syntax"><table><tr><td><div class="code"><pre class="csharp" style="font-family:Consolas; monospace;"><span style="color: #FF0000;">string</span> output<span style="color: #008000;">=</span>ReverseWordByWord<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;This is an eXclusiveMinds article&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>output<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></td></tr></table></div>

<p>OUTPUT:</p>

<div class="wp_syntax"><table><tr><td><div class="code"><pre class="csharp" style="font-family:Consolas; monospace;"><span style="color: #008080; font-style: italic;">//input: This is an eXclusiveMinds article</span>
article eXclusiveMinds an <span style="color: #008000;">is</span> <span style="color: #0600FF;">This</span></pre></div></td></tr></table></div>

<img src="http://eXclusiveMinds.Com/?ak_action=api_record_view&id=347&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://eXclusiveMinds.com/2009/12/09/program-to-reverse-sentence-word-by-word-using-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
