String.Substring()不存在错误 [英] String.Substring() Does not exist error

查看:119
本文介绍了String.Substring()不存在错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




使用C#我正在尝试使用字符串变量的子字符串方法,但它只需要生成一个错误:
''variable.Substring''不存在异常 -

如何解决这个问题?


代码示例:


string creationDateStr = string.Empty;

string anotherStr ="" ;;

creationDateStr =" some string or other" ;;

anotherStr = creationDateStr.Substring(0, 2);


这在运行时编译但是错误。


谢谢,



Hi,

Using C# I''m trying to use the substring method of a string variable but it
just generates an "error: ''variable.Substring'' does not exist " exception -
how do I fix this ?

code example:

string creationDateStr = string.Empty;
string anotherStr = "";
creationDateStr = "some string or other";
anotherStr = creationDateStr.Substring(0,2);

This compiles but errors at run time.

Thanks,



推荐答案



你必须确保你的字符串变量中有东西。


if len(creationdatestr)> 2然后

creationdatestr.substring(0,2)

else

messagebox.show(字符串不够长)

结束如果


这是vb语法...我相信你可以把它改成c#;-)


Duncan Allen写道:

you have to make sure that there is something in your string variable.

if len(creationdatestr) > 2 then
creationdatestr.substring(0,2)
else
messagebox.show("string not long enough")
end if

this is vb syntax... I''m sure you can change it to c# ;-)

"Duncan Allen" wrote:


使用C#我试图使用字符串变量的子字符串方法,但它只是生成一个 ;错误:''variable.Substring''不存在异常 -
如何解决这个问题?

代码示例:

string creationDateStr = string.Empty;
string anotherStr ="" ;;
creationDateStr =" some string or other" ;;
anotherStr = creationDateStr.Substring(0,2);

这会在运行时编译但错误。
<谢谢,

Hi,

Using C# I''m trying to use the substring method of a string variable but it
just generates an "error: ''variable.Substring'' does not exist " exception -
how do I fix this ?

code example:

string creationDateStr = string.Empty;
string anotherStr = "";
creationDateStr = "some string or other";
anotherStr = creationDateStr.Substring(0,2);

This compiles but errors at run time.

Thanks,



谢谢,但字符串变量已经填充,仍然没有欢乐。


" interwanderer"写道:
Thanks, but the string variables are populated and still no joy.

"interwanderer" wrote:

你必须确保你的字符串变量中有东西。

如果len(creationdatestr)> 2然后
creationdatestr.substring(0,2)
否则
messagebox.show(字符串不够长)
结束如果

这个是vb语法......我相信你可以把它改成c#;-)

Duncan Allen写道:

you have to make sure that there is something in your string variable.

if len(creationdatestr) > 2 then
creationdatestr.substring(0,2)
else
messagebox.show("string not long enough")
end if

this is vb syntax... I''m sure you can change it to c# ;-)

"Duncan Allen" wrote:


使用C#我试图使用字符串变量的子字符串方法,但它只是生成一个 ;错误:''variable.Substring''不存在异常 -
如何解决这个问题?

代码示例:

string creationDateStr = string.Empty;
string anotherStr ="" ;;
creationDateStr =" some string or other" ;;
anotherStr = creationDateStr.Substring(0,2);

这会在运行时编译但错误。

谢谢,

Hi,

Using C# I''m trying to use the substring method of a string variable but it
just generates an "error: ''variable.Substring'' does not exist " exception -
how do I fix this ?

code example:

string creationDateStr = string.Empty;
string anotherStr = "";
creationDateStr = "some string or other";
anotherStr = creationDateStr.Substring(0,2);

This compiles but errors at run time.

Thanks,





使用以下功能之一。左,右或中。


" Duncan Allen"写道:

use one of the following functions. left, right or mid.

"Duncan Allen" wrote:
谢谢,但字符串变量已填充,仍然没有欢乐。

interwanderer写道:
Thanks, but the string variables are populated and still no joy.

"interwanderer" wrote:

你必须确保你的字符串变量中有东西。

如果len(creationdatestr)> 2然后
creationdatestr.substring(0,2)
否则
messagebox.show(字符串不够长)
结束如果

这个是vb语法......我相信你可以把它改成c#;-)

Duncan Allen写道:

you have to make sure that there is something in your string variable.

if len(creationdatestr) > 2 then
creationdatestr.substring(0,2)
else
messagebox.show("string not long enough")
end if

this is vb syntax... I''m sure you can change it to c# ;-)

"Duncan Allen" wrote:


使用C#我试图使用字符串变量的子字符串方法,但它只是生成一个 ;错误:''variable.Substring''不存在异常 -
如何解决这个问题?

代码示例:

string creationDateStr = string.Empty;
string anotherStr ="" ;;
creationDateStr =" some string or other" ;;
anotherStr = creationDateStr.Substring(0,2);

这会在运行时编译但错误。
<谢谢,

Hi,

Using C# I''m trying to use the substring method of a string variable but it
just generates an "error: ''variable.Substring'' does not exist " exception -
how do I fix this ?

code example:

string creationDateStr = string.Empty;
string anotherStr = "";
creationDateStr = "some string or other";
anotherStr = creationDateStr.Substring(0,2);

This compiles but errors at run time.

Thanks,



这篇关于String.Substring()不存在错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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