Click here to Skip to main content
15,887,328 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have been analysing a code in that a double value is being changed to string and is split and then stored into database.


ex:dim a as double=123.23
dim b() as string
b=a.tosting().split(".")

this can be done like this aslo
i.e
dim a as double=123.23
dim b as string
b=a.tostring()

can anyone plz help me find what is the use of split() in this case.
Posted
Comments
Sergey Alexandrovich Kryukov 16-Sep-12 23:51pm    
First, what's the problem? did you simply read the MSDN help on it? -- would be too trivial.
Second, why would you use double.ToString? Chances are, you don't need it. It's always good to explain your goals, to get better answers.
--SA
Member 8953399 17-Sep-12 0:51am    
in my application values are stored in database by conversion of double value to string.if double can be directly changed into string using tostring() then why split() is used.i want the usage of split used here.
b = a.ToString().Split("."C)

1 solution

Hi,

see this sample:
VB
Dim a As Double = 123.23
Dim b As String() = Nothing
b = a.ToString().Split("."C)
Dim part1 As String = b(0)
Dim part2 As String = b(1)
MessageBox.Show(part1 + "  " + part2)

Basically in this case, split separates the part before and after the period, so that in b(0) you have "123" and in b(1) you have "23". Please take care of regional settings where 123.23 may be displayed as 123,23 (e.g. this is the case in Germany).
 
Share this answer
 
Comments
Member 8953399 17-Sep-12 6:42am    
plz give the usage of split() here.
JF2015 17-Sep-12 6:47am    
It is just to separate the part before and after the period.
Member 8953399 17-Sep-12 6:50am    
this conversion of double to string can be done using tostring().but still why we require split().plz help
JF2015 17-Sep-12 7:31am    
You don't need it. It may just be used if you want to have two separate strings. One before and one after the period.
Member 8953399 17-Sep-12 12:38pm    
plz dont mind bcz the code am analysing this code and in that split is used.

Dim avgBVsplit(2) As String
avgBVsplit = SumPC.ToString().Split(".")
If avgBVsplit.Count = 2 Then
If avgBVsplit(1).Length > 2 Then
frmRMM.tslPC.Text = "PC(Sum) : " + avgBVsplit(0) + "." + avgBVsplit(1).Substring(0, 2)
Else
frmRMM.tslPC.Text = "PC(Sum) : " + SumPC.ToString()
End If
Else
frmRMM.tslPC.Text = "PC(Sum) : " + SumPC.ToString()
End If

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900