请删除文字为空的错误 [英] please remove error that is literal is empty

查看:64
本文介绍了请删除文字为空的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

推荐答案

字符串,我假设您想在每个空格字符处分割字符串,因此您需要执行以下操作:

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(" ");


< pre lang ="cs">使用系统;
使用System.Data;
使用System.Configuration;
使用System.Web;
使用System.Web.Security;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Web.UI.HtmlControls;
使用System.Web.UI.WebControls.WebParts;
使用System.IO;

公共局部类_Default:System.Web.UI.Page
{
//声明一个对象.
< u> TranslatorClass</u> TransClass;我在评论中提到的错误
受保护的void Page_Load(对象发送者,EventArgs e)
{
//首次显示此页面
如果(!IsPostBack)
{
//创建一个新的翻译器对象.
TransClass =新的TranslaterClass();
//将对象存储在会话状态变量中.
会话[&"TransClass&"] = TransClass;
}
其他
//获取会话TransClass变量.
TransClass =(TranslatorClass)Session [& quot; TransClass& quot;];
}

受保护的void butTranslate_Click(对象发送者,EventArgs e)
{
//声明一个布尔开关.
bool bSwitch;
///检查是否存在viewState变量
if(ViewState [& quot; bSwitch& quot;]!= null)
//从ViewState获取值并进行切换.
bSwitch =!(bool)ViewState [& quot; bSwitch& quot;] ;;
其他
//设置开关
bSwitch = true;
//将新值保存在viewstate
ViewState [& quot; bSwitch& quot;] = bSwitch;
//使用SWitch进行翻译或恢复
//txtSource中的文本.
如果(bSwitch)
{
//获取文字.
TransClass.Text = txtSource.Text;
//翻译.
TransClass.Translate();
//显示文字.
txtSource.Text = TransClass.Text;
//更改按钮文字".
butTranslate.Text =& quot;恢复& quot ;;
}
其他
{
//恢复原始文本.
TransClass.Restore();
//显示文字
txtSource.Text = TransClass.Text;
//更改按钮文字.
butTranslate.Text =& quot; Translate& quot ;;
}
}
}</pre>

< b>< u>和TranslatorClass.cs编码</u> </b>
< pre lang ="cs">使用系统;
使用System.Data;
使用System.Configuration;
使用System.Web;
使用System.Web.Security;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Web.UI.WebControls.WebParts;
使用System.Web.UI.HtmlControls;
使用System.IO;
内部类TranslatorClass
{
字符串mstrText;
字符串mstrOriginal;
//控制对类级变量的访问.
公共字符串Text
{
获取
{
返回mstrText;
}
设置
{
mstrText =值;
//保留原始还原的副本.
mstrOriginal =值;
}
}
//将翻译后的文本恢复为原始文本.
公共无效Restore()
{
mstrText = mstrOriginal;
}
//翻译text属性中的值.
公共无效Translate()
{
字符串strWord;
字符串[] arrWords;
bool bCaps = false;
//使用System.String将字符串转换为数组.
arrWords = mstrText.Split(&&"));
for(int intCount = 0; intCount& lt; = arrWords.GetUpperBound(0); intCount ++)
{
//更改为小写字母.
strWord = arrWords [intCount] .ToLower();
//检查单词是否大写.
如果(!arrWords [intCount] .Equals(strWord))
bCaps = true;
//执行翻译.
if(strWord!=&&"))
{
strWord = strWord.Substring(1,strWord.Length-1)+ strWord.Substring(0,1)+& quot; ay& quot ;;
//如有必要,请进行资本重组.
如果(bCaps)
strWord = strWord.Substring(0,1).ToUpper()+ strWord.SubString(1,strWord.Length-1);
}
//将单词重新存储在数组中
arrWords [intCount] = strWord;
//重置大写字母标志.
bCaps = false;
}
//从数组中重建字符串.
mstrText = String.Join(&&",arrWords);
}
}</pre>
<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>


这篇关于请删除文字为空的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆