Click here to Skip to main content
14,661,186 members
Rate this:
Please Sign up or sign in to vote.
See more:
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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(" ");
   
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)
............................................
Rate this:
Please Sign up or sign in to vote.

Solution 2

<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>
   
v2

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100