Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

internal class TranslaterClass
{
    string mstrText;
    string mstrOriginal;
    //Control access to class-level variables.
public string Text
{
    get
    {
    return mstrText ;
    }
     set
    {
mstrText = value;
// keep a copy of the original Restore .
mstrOriginal = value;
}
}
//Restores translated text back to the original .
public void Restore()
{
mstrText = mstrOriginal;
}
// Translates the value  in the text property .
public void Translate()
{
string strWord;
string[] arrWords;
bool bCaps = false;
//Convert the  string into an array using System.String.
    arrWords = mstrText.Split (error that empty character literral ) how it pics data at runtime ,, just bcs of this error , i m unable to run my web application)
for(int intCount = 0; intCount <= arrWords.GetUpperBound(0));intCount++)
{
// Change to lowercase.
strWord =  arrWords[intCount].ToLower();
//Check if the word is capitalized .
if(!arrWords[intCount].Equals(strWord))
bCaps = true;
// Do the transalation.
if(strWord != "")
{
strWord = strWord.Substring(1,strWord.Length - 1) + strWord.Substring(0,1) + "ay";
//Recapitalize if necessary .
if(bCaps)
strWord = strWord.Substring(0,1).ToUpper () + strWord.SubString(1,strWord.Length - 1);
}
// store the word back in the array
arrWords[intCount] = strWord;
//Reset the caps flag.
bCaps = false;
}
//Rebuild the string from the array .
mstrText = String.Join("",arrWords);
}
}
please remove this error onlyy,,................ send me d corrected 1 , after removng error ...
ohk , pls do that in free time , if u will get time.
Posted

Since you apparanetly want the words in the string, I'm assuming you want to split the string at every space character, so you need to do this:

arrWords = mstrText.Split(" ");
 
Share this answer
 
Comments
pinky_sood 2-May-11 6:20am    
i was doing as arrWords = mstrText.Split(''); previouslly . when i have added my qo, got edit by mistake that (''); alright . but when i am using this declaration [arrWords = mstrText.Split(" "); ] stil i m getting the error ,,,,that is type/namespace could not be found in(are u missing using directive or reference)
............................................
<pre lang="cs">using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
// declare an object .
<u> TranslatorClass</u> TransClass; error which i have mentioned in comment
protected void Page_Load(object sender, EventArgs e)
{
// the first time this page is displayed
if (!IsPostBack)
{
//Create a new translater object.
TransClass = new TranslaterClass();
//Store the object in a Session state variable.
Session[&quot;TransClass&quot;] = TransClass;
}
else
//Get the Session TransClass variables.
TransClass = (TranslatorClass)Session[&quot;TransClass&quot;];
}

protected void butTranslate_Click(object sender, EventArgs e)
{
//Declare a boolean switch.
bool bSwitch;
///Check if viewState variable exists
if (ViewState[&quot;bSwitch&quot;] != null)
// Get the value from ViewState and switch it.
bSwitch = !(bool)ViewState[&quot;bSwitch&quot;];
else
//set the switch
bSwitch = true;
//save the new value in viewstate
ViewState[&quot;bSwitch&quot;] = bSwitch;
//Use the SWitch to either translate or restore
// the text in txtSource.
if (bSwitch)
{
//Get the text .
TransClass.Text = txtSource.Text;
//Translate it .
TransClass.Translate();
//Display the text .
txtSource.Text = TransClass.Text;
//change the button Text.
butTranslate.Text = &quot;Restore&quot;;
}
else
{
//Restore the original text.
TransClass.Restore();
//Display the text
txtSource.Text = TransClass.Text;
//Change the button text.
butTranslate.Text = &quot;Translate&quot;;
}
}
}</pre>

<b><u>and TranslatorClass.cs coding</u> </b>
<pre lang="cs">using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
internal class TranslatorClass
{
string mstrText;
string mstrOriginal;
//Control access to class-level variables.
public string Text
{
get
{
return mstrText;
}
set
{
mstrText = value;
// keep a copy of the original Restore .
mstrOriginal = value;
}
}
//Restores translated text back to the original .
public void Restore()
{
mstrText = mstrOriginal;
}
// Translates the value in the text property .
public void Translate()
{
string strWord;
string[] arrWords;
bool bCaps = false;
//Convert the string into an array using System.String.
arrWords = mstrText.Split(&quot;&quot;);
for (int intCount = 0; intCount &lt;= arrWords.GetUpperBound(0); intCount++)
{
// Change to lowercase.
strWord = arrWords[intCount].ToLower();
//Check if the word is capitalized .
if (!arrWords[intCount].Equals(strWord))
bCaps = true;
// Do the transalation.
if (strWord != &quot;&quot;)
{
strWord = strWord.Substring(1, strWord.Length - 1) + strWord.Substring(0, 1) + &quot;ay&quot;;
//Recapitalize if necessary .
if (bCaps)
strWord = strWord.Substring(0, 1).ToUpper() + strWord.SubString(1, strWord.Length - 1);
}
// store the word back in the array
arrWords[intCount] = strWord;
//Reset the caps flag.
bCaps = false;
}
//Rebuild the string from the array .
mstrText = String.Join(&quot;&quot;, arrWords);
}
}</pre>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900