字符串方法 [英] String methods

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

问题描述

我是否遗漏了某些东西,或者.Net框架中的方法是否在某个对象上运行方式。在C ++ MFC中,如果我有CString并且我使用格式方法,我格式化我正在使用的字符串。在dotnet它

总是要求我传递它的字符串。为什么我不能只是说

" stringvariable.Format(" 0.00")并让它知道我的意思。有没有

实现这个目标的方法?我做错了什么

Am i missing something or does the .Net Framework have a quirk in the
way methods work on an object. In C++ MFC, if i have a CString and i
use the format method, i format the string i am using. In dotnet it
always asks me to pass it the string. Why can''t i just say
"stringvariable.Format("0.00") and have it know what i mean. Is there
a way to achieve this? What am i doing wrong

推荐答案

" Tubs" < TS ******* @ commandalkon.com> schrieb
"Tubs" <ts*******@commandalkon.com> schrieb
我错过了什么或者.Net Framework在方法处理对象的方式上有一个怪癖。在C ++ MFC中,如果我有一个CString
我使用格式方法,我格式化我正在使用的字符串。在
dotnet中,它始终要求我将字符串传递给它。为什么我不能只说
stringvariable.Format(" 0.00")并让它知道我的意思。有没有办法实现这个目标?我做错了什么
Am i missing something or does the .Net Framework have a quirk in
the way methods work on an object. In C++ MFC, if i have a CString
and i use the format method, i format the string i am using. In
dotnet it always asks me to pass it the string. Why can''t i just
say "stringvariable.Format("0.00") and have it know what i mean. Is
there a way to achieve this? What am i doing wrong




一个字符串已经是一个字符串,所以格式化它没有意义(恕我直言)

再次 - 不是使用

指定的格式将数值转换为字符串。 String.Format函数是从

其他字符串组成一个字符串。


你可以格式化一个数字变量:

numvariable .ToString(" 0.00")

-

Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html



A string is already a string, so it doesn''t make sense (IMHO) to format it
again - not in the sense of converting a numeric value into a string using a
specified format. The String.Format function is to compose a string from
other strings.

You can format a numeric variable:
numvariable.ToString("0.00")
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html


* ts*******@commandalkon.com (Tubs)scripsit:
* ts*******@commandalkon.com (Tubs) scripsit:
我错过了什么,或者.Net Framework在方法上对方法起作用的方式有一个怪癖。在C ++ MFC中,如果我有CString并且我使用格式方法,我格式化我正在使用的字符串。在dotnet中,它总是要求我传递它的字符串。为什么我不能只说
" stringvariable.Format(" 0.00")并让它知道我的意思。有没有办法实现这个目标?我做错了什么
Am i missing something or does the .Net Framework have a quirk in the
way methods work on an object. In C++ MFC, if i have a CString and i
use the format method, i format the string i am using. In dotnet it
always asks me to pass it the string. Why can''t i just say
"stringvariable.Format("0.00") and have it know what i mean. Is there
a way to achieve this? What am i doing wrong




您可以使用''intvariable.ToString(< format>)''。


请注意,一方面有'String'类,其方法为

,另一方面有

Visual Basic提供的字符串_functions_。 NET运行时库。 ''Strings.Format''由VB $ VB $ VB $ VB提供,而不是''String''类。


-

Herfried K. Wagner

MVP·VB Classic,VB.NET

< http://www.mvps.org/dotnet>


< http://www.plig.net/nnq/nquote.html>



You can use ''intvariable.ToString(<format>)''.

Notice that on the one hand there is the ''String'' class with its methods
and on the other hand there are the string _functions_ provided by the
Visual Basic .NET runtime library. ''Strings.Format'' is provided by
VB.NET, not the ''String'' class.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>


我假设你正在努力工作w VB.NET在这里而不是C ++ .NET
i''m assuming you are trying to work w VB.NET here and not w C++.NET
是否有实现这一目标的方法?我做错了什么


如果你创建自己的字符串类并给它一个格式函数你可以

得到你正在寻找的行为


public sub farmatting(形式为字符串)

thestring = format(thestring,form)

end sub

公共覆盖函数ToString()As String

返回字符串

结束函数


等等..

为什么我们只能说
" stringvariable.Format(" 0.00")并让它知道我的意思。
Is there
a way to achieve this? What am i doing wrong
if you create your own string class and give it a format function you could
get the behaviour you are looking for

public sub farmatting(form as string)
thestring = format(thestring, form)
end sub

Public Overrides Function ToString() As String
Return thestring
End Function

and so on ..
Why can''t i just say
"stringvariable.Format("0.00") and have it know what i mean.



为什么会这样,我会认为因为它的VB.net,除非我有严重的

内存问题就像在vb6和vb5和vb4中那样

eric



why is it this way, i would think becouse its VB.net, unless i have serious
memory problems it was like that in vb6 and vb5 and vb4
eric


这篇关于字符串方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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