string problem - please help

  • Thread starter Thread starter Russell Jones
  • Start date Start date
R

Russell Jones

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
 
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.
 
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 :-\) said:
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
///
 
Tiraman,
A couple of other possiblities:
Dim mystring as string = "" Dim delim as string
for i=1 to 3
mystring = mystring & delim & otherstring delim = ","
next i


Dim strings(2) As String
strings(0) = otherstring1
strings(1) = otherstring2
strings(2) = otherstring3

mystring = String.Join(",", strings)

I prefer String.Join when my strings are already in an array, other wise I
use the first one.

Hope this helps
Jay
 
Hi Tiraman,

Can you learn me how you do that?
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,"

Cor
 
Learn you what ?

Get that a,b,c result with that code.

I was searching how you did that, however without any result.
When I use the codes samples others provided to you it is of course no
problem even not doing it like this (I thought the sample Herfried showed
you)

\\\
mystring = "a"
for i = 2 to 3
mystring = "," & chrw(i+96)
next
///
However the way you did it I could not succeed.

:-)

Cor
 
hi every one,

thanks for the examples.
all of the examples are good.

bye and thanks again :-)
T :-)
 
hi,
if i understand you then my code didn't get me a good result and bcz of that
i asked you guys for help.
bye
 
Hi

Tiraman, in my opinion would the sample you gave never give the result you
said, therefore it was extra difficult to help you because I could not get
the problem. (You got answers however they where not telling why the one was
different from the other one).

However no problem of course.

:-)

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top