473,513 Members | 10,313 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

string problem - please help

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 :-)

Nov 21 '05 #1
10 1026
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 :-)


Nov 21 '05 #2
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 :-)


Nov 21 '05 #3
* "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/>
Nov 21 '05 #4
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

"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 :-)


Nov 21 '05 #5
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
Nov 21 '05 #6
hi every one,

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

bye and thanks again :-)
T :-)

"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 :-)


Nov 21 '05 #7
Hi Cor,

Learn you what ?

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uu**************@TK2MSFTNGP09.phx.gbl...
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

Nov 21 '05 #8
>
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

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,"


Nov 21 '05 #9
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

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uz**************@TK2MSFTNGP10.phx.gbl...

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

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,"


Nov 21 '05 #10
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

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

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uz**************@TK2MSFTNGP10.phx.gbl...

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
>
> 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,"
>



Nov 21 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
9571
by: Ahmad A. Rahman | last post by:
Hi All, I have a string as and I want to split the string, which will turn into an array of: Arr = "1"; Arr = "two"; Arr = "three"; Arr = "fo""ur"; Arr = "fi,ve";
6
43143
by: LCD | last post by:
This a rather simple question for all you studs out there! Please help me with this. I have a string = "Please help me", and I want to convert this into it's hex equivalent. How do I do it, I...
5
2396
by: geotso | last post by:
Here is the scenario: 1. I have a table (tblCalendar) with the following fields: caldID caldDate caldTitle caldInfo nWinW nWinH
8
8300
by: vidya.bhagwath | last post by:
Hello Experts, I am using std::string object as a member variable in one of the my class. The same class member function operates on the std::string object and it appends some string to that...
9
3864
by: MikeB | last post by:
Hi, I'd appreciate some help, please. I'm writing a VS2005 VB project for school and one of the requirements is that every screen should have a "Help" button. I could do it by writing a clumsy...
8
4980
by: Lucky | last post by:
hi guys! back again with another query. the problem is like this. i want to print a line like this: "---------------------------------------------" the easiest way is to simply assign it to...
11
5033
by: Sudzzz | last post by:
Hi, I'm trying to convert a string something like this "{201,23,240,56,23,45,34,23}" into an array in C++ Please help. Thanks, Sudzzz
6
1597
by: djm | last post by:
hello everyone, im doing a c++ coursework which consists linked lists and use of classes. but im getting some compilation errors. can some please help me out. //this is the header file...
8
6321
by: Brett | last post by:
I wrote an ASP.NET application that queries a SQL Server database (on a different box from the web server) and displays the result in a GridView. The datasource for the GridView is a SQLDataSource....
5
5003
by: mvmashraf | last post by:
Hi to all.... I have spent some time browsing for a solution to the following error but have unfortunatly not found any solution yet ,Please any help would be much appreciated.......
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.