473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

String variable into integer array

Hi!

I'm wondering how can I get integer type of array easier of the numbers
in string type variable when numbers are separated with comma ",".

I made it like code below, but obviously there is an easier way to do it.

'// Readed string from ConfigurationSettings
Dim strNums As String = "10,20,30,40"

Dim arrStr As String() = strNums.Split(Char.Parse(","))
Dim arrInt(arrStr.Length - 1) As Integer

For i As Integer = 0 To arrStr.Length - 1
arrInt(i) = CType(arrStr(i), Integer)
Next

....code continues

--
Thanks in advance!

Mika
Nov 21 '05 #1
3 1233
There are slight variations on what you have done, but I dont think there is
a more streamline way code wise to convert arrays of those types.

"Mika M" <ma***************@luukku.com> wrote in message
news:eb**************@TK2MSFTNGP14.phx.gbl...
Hi!

I'm wondering how can I get integer type of array easier of the numbers in
string type variable when numbers are separated with comma ",".

I made it like code below, but obviously there is an easier way to do it.

'// Readed string from ConfigurationSettings
Dim strNums As String = "10,20,30,40"

Dim arrStr As String() = strNums.Split(Char.Parse(","))
Dim arrInt(arrStr.Length - 1) As Integer

For i As Integer = 0 To arrStr.Length - 1
arrInt(i) = CType(arrStr(i), Integer)
Next

...code continues

--
Thanks in advance!

Mika

Nov 21 '05 #2
Hi,

I dont see a better way. Just thought you should know that you can
replace Char.Parse(",") with ","c

Ken
-------------
"Mika M" <ma***************@luukku.com> wrote in message
news:eb**************@TK2MSFTNGP14.phx.gbl...
Hi!

I'm wondering how can I get integer type of array easier of the numbers in
string type variable when numbers are separated with comma ",".

I made it like code below, but obviously there is an easier way to do it.

'// Readed string from ConfigurationSettings
Dim strNums As String = "10,20,30,40"

Dim arrStr As String() = strNums.Split(Char.Parse(","))
Dim arrInt(arrStr.Length - 1) As Integer

For i As Integer = 0 To arrStr.Length - 1
arrInt(i) = CType(arrStr(i), Integer)
Next

...code continues

--
Thanks in advance!

Mika

Nov 21 '05 #3
"Mika M" <ma***************@luukku.com> schrieb:
I'm wondering how can I get integer type of array easier of the numbers in
string type variable when numbers are separated with comma ",".

I made it like code below, but obviously there is an easier way to do it.

'// Readed string from ConfigurationSettings
Dim strNums As String = "10,20,30,40"

Dim arrStr As String() = strNums.Split(Char.Parse(","))
Dim arrInt(arrStr.Length - 1) As Integer

For i As Integer = 0 To arrStr.Length - 1
arrInt(i) = CType(arrStr(i), Integer)
Next


I think the solution is basically OK. However, some suggestions:

* I would use '","c' instead of 'Char.Parse(",")'. Appending the 'c' to
the
one-character string literal will make it a character literal. No need
for
a conversion at runtime.

* Instead of 'CType(arrStr(i), Integer)' you could write 'CInt(arrStr(i))'
which makes code shorter and IMO more readable.

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

Nov 21 '05 #4

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

Similar topics

23
by: Nascimento | last post by:
Hello, How to I do to return a string as a result of a function. I wrote the following function: char prt_tralha(int num) { int i; char tralha;
9
by: rsine | last post by:
I have developed a program that sends a command through the serial port to our business system and then reads from the buffer looking for a number. Everything worked great on my WinXP system, but...
11
by: RipperT | last post by:
Don't know if this group covers web apps, but here goes. In VS 2005, I am trying to get variables to hold thier values during postback from the server. I convert a text box's user-keyed value to an...
12
by: Pascal | last post by:
hello and soory for my english here is the query :"how to split a string in a random way" I try my first shot in vb 2005 express and would like to split a number in several pieces in a random way...
4
Dheeraj Joshi
by: Dheeraj Joshi | last post by:
Hi, I was wondering is there any technique available, so we can access the global variable inside a function if we have a local variable inside the function with the same name as global variable. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...

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.