字符串问题 - 请帮助 [英] string problem - please help

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

问题描述




我有一点问题就是用一些,来连接一个字符串。这是我的代码:


Dim mystring as string =""

for i = 1到3

mystring = mystring& "," &安培; Otherstring

next i


我正在得到这样的结果


" a,b,c,


和数字我得到这个结果


",1,2,3"


我怎样才能做到a,b,c和1,2,3 ?


谢谢。

T :-)

解决方案

< blockquote>也许是这样的:


dim mystring as string =""

for i = 1 to 3

如果len(mystring)= 0那么

mystring = Cstr(i)

else

mystring = mystring& , &安培; CStr(i)

结束如果

下一个我


这将给你1,2,3


希望这会有所帮助..

Imran。


Tiraman: - ) < TI ***** @ netvision.net.il>在消息中写道

新闻:uT ************** @ TK2MSFTNGP10.phx.gbl ...

hi,

我有一个小问题,用一些,来连接一个字符串。这是我的代码:

Dim mystring as string =""
for i = 1 to 3
mystring = mystring& ; "," &安培; Otherstring
接下来我就得到这样的结果

a,b,c,"

和得到这个结果的数字

",1,2,3"

如何使它成为a,b,c和1,2,3 ?

谢谢。
T :-)



这里是'单程。请注意,该功能不做任何检查或修剪,

所以它会愉快地附加空字符串或字符串,只包含

空格。另请注意,如果你要做很多这些字符串

连接,你应该使用StringBuilder。


函数AppendCommaDelimitedValue(ByVal s作为String,ByVal appendValue

As String)As String

如果s.Length = 0那么

s = appendValue

Else

s = s& "," &安培; appendValue

结束如果

返回s

结束功能

Tiraman: - ) < TI ***** @ netvision.net.il>在消息中写道

新闻:uT ************** @ TK2MSFTNGP10.phx.gbl ...

hi,

我有一个小问题,用一些,来连接一个字符串。这是我的代码:

Dim mystring as string =""
for i = 1 to 3
mystring = mystring& ; "," &安培; Otherstring
接下来我就得到这样的结果

a,b,c,"

和得到这个结果的数字

",1,2,3"

如何使它成为a,b,c和1,2,3 ?

谢谢。
T :-)



*" Tiraman :-\)" < TI ***** @ netvision.net.il> scripsit:

我有一个问题,就是用一些,来连接一个字符串。这是我的代码:

Dim mystring as string =""
for i = 1 to 3
mystring = mystring& ; "," &安培; Otherstring
接下来我就得到这样的结果

a,b,c,"

和得到这个结果的数字

",1,2,3"

如何使它成为a,b,c和1,2,3 ?




\\\

Dim MyString As String = OtherString

for i = 2 to 3

MyString& =","

MyString& = OtherString

Next i

/ //


-

MS Herfried K. Wagner

MVP< URL:http://dotnet.mvps。 org />

VB< URL:http://dotnet.mvps.org/dotnet/faqs/>


hi,

i have a little problem to concat a string with some "," sign.

this is my code:

Dim mystring as string = ""
for i=1 to 3
mystring = mystring & "," & otherstring
next i

and i m getting the result like this

"a,b,c,"

and with numbers i m getting this result

",1,2,3"

how can i make it "a,b,c" and "1,2,3" ?

Thanks.
T :-)

解决方案

maybe something like this:

dim mystring as string = ""
for i=1 to 3
if len(mystring) = 0 then
mystring = Cstr(i)
else
mystring = mystring & ", " & CStr(i)
end if
next i

this will give you 1,2,3

hope this helps..
Imran.

"Tiraman :-)" <ti*****@netvision.net.il> wrote in message
news:uT**************@TK2MSFTNGP10.phx.gbl...

hi,

i have a little problem to concat a string with some "," sign.

this is my code:

Dim mystring as string = ""
for i=1 to 3
mystring = mystring & "," & otherstring
next i

and i m getting the result like this

"a,b,c,"

and with numbers i m getting this result

",1,2,3"

how can i make it "a,b,c" and "1,2,3" ?

Thanks.
T :-)



Here''s one way. Note that the function doesn''t do any checking or trimming,
so it will happily append empty strings or strings containing nothing but
white space. Also note that if you''re going to do very many of these string
concatenations, you should use a StringBuilder instead.

Function AppendCommaDelimitedValue(ByVal s As String, ByVal appendValue
As String) As String
If s.Length = 0 Then
s = appendValue
Else
s = s & "," & appendValue
End If
Return s
End Function
"Tiraman :-)" <ti*****@netvision.net.il> wrote in message
news:uT**************@TK2MSFTNGP10.phx.gbl...

hi,

i have a little problem to concat a string with some "," sign.

this is my code:

Dim mystring as string = ""
for i=1 to 3
mystring = mystring & "," & otherstring
next i

and i m getting the result like this

"a,b,c,"

and with numbers i m getting this result

",1,2,3"

how can i make it "a,b,c" and "1,2,3" ?

Thanks.
T :-)



* "Tiraman :-\)" <ti*****@netvision.net.il> scripsit:

i have a little problem to concat a string with some "," sign.

this is my code:

Dim mystring as string = ""
for i=1 to 3
mystring = mystring & "," & otherstring
next i

and i m getting the result like this

"a,b,c,"

and with numbers i m getting this result

",1,2,3"

how can i make it "a,b,c" and "1,2,3" ?



\\\
Dim MyString As String = OtherString
For i = 2 to 3
MyString &= ","
MyString &= OtherString
Next i
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


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

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