473,407 Members | 2,629 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,407 software developers and data experts.

breaking up a String into an array of chars and adding to datatable

Hello,

I have a string that I am trying to add each char to a datatable row.

for example if I have a string that looks like "abcdefg", I would like
to break it up into an array of characters so I can do this:

myDataTable.Rows.Add(array())

instead of myDataTable.Rows.Add("a","b","c","d","e","f","g")

You help is greatly appreciated!

thanks :)

Jan 14 '07 #1
6 2338
You need to convert the string to an array of characters:

Dim chararray As Char() = MyString.ToCharArray()

and then feed the array of characters to the Rows.Add method:

myDataTable.Rows.Add(chararray)

If you do not need to 'save' the interim result for another purpose then you
could feed it in directly:

myDataTable.Rows.Add(MyString.ToCharArray())

character
"Paulers" <Su*******@gmail.comwrote in message
news:11**********************@s34g2000cwa.googlegr oups.com...
Hello,

I have a string that I am trying to add each char to a datatable row.

for example if I have a string that looks like "abcdefg", I would like
to break it up into an array of characters so I can do this:

myDataTable.Rows.Add(array())

instead of myDataTable.Rows.Add("a","b","c","d","e","f","g")

You help is greatly appreciated!

thanks :)

Jan 15 '07 #2
Hello and thanks for your response!

I gave that a try and when I display my DataGridView it shows
System.Char[] in the first col.

Here is what I did

Dim d As DataTable = New DataTable
Dim line As String = "abcdefg"
d.Rows.Add(line.ToCharArray())
Me.DataGridView1.DataSource = d

Stephany Young wrote:
You need to convert the string to an array of characters:

Dim chararray As Char() = MyString.ToCharArray()

and then feed the array of characters to the Rows.Add method:

myDataTable.Rows.Add(chararray)

If you do not need to 'save' the interim result for another purpose then you
could feed it in directly:

myDataTable.Rows.Add(MyString.ToCharArray())

character
"Paulers" <Su*******@gmail.comwrote in message
news:11**********************@s34g2000cwa.googlegr oups.com...
Hello,

I have a string that I am trying to add each char to a datatable row.

for example if I have a string that looks like "abcdefg", I would like
to break it up into an array of characters so I can do this:

myDataTable.Rows.Add(array())

instead of myDataTable.Rows.Add("a","b","c","d","e","f","g")

You help is greatly appreciated!

thanks :)
Jan 15 '07 #3
Sorry, you can't do this directly with the Rows.Add method.

You have to do it indirectly, something like:

Dim d As DataTable = New DataTable
Dim line As String = "abcdefg"
For i As Integer = 0 to line.Length - 1
d.Columns.Add(New DataColumn("c" & i.ToString,
Type.GetType("System.Char")))
Next
Dim dr As DataRow = _d.NewRow()
dr.ItemArray = line.ToCharArray()
d.Rows.Add(_dr)
Me.DataGridView1.DataSource = d
"Paulers" <Su*******@gmail.comwrote in message
news:11*********************@l53g2000cwa.googlegro ups.com...
Hello and thanks for your response!

I gave that a try and when I display my DataGridView it shows
System.Char[] in the first col.

Here is what I did

Dim d As DataTable = New DataTable
Dim line As String = "abcdefg"
d.Rows.Add(line.ToCharArray())
Me.DataGridView1.DataSource = d

Stephany Young wrote:
>You need to convert the string to an array of characters:

Dim chararray As Char() = MyString.ToCharArray()

and then feed the array of characters to the Rows.Add method:

myDataTable.Rows.Add(chararray)

If you do not need to 'save' the interim result for another purpose then
you
could feed it in directly:

myDataTable.Rows.Add(MyString.ToCharArray())

character
"Paulers" <Su*******@gmail.comwrote in message
news:11**********************@s34g2000cwa.googleg roups.com...
Hello,

I have a string that I am trying to add each char to a datatable row.

for example if I have a string that looks like "abcdefg", I would like
to break it up into an array of characters so I can do this:

myDataTable.Rows.Add(array())

instead of myDataTable.Rows.Add("a","b","c","d","e","f","g")

You help is greatly appreciated!

thanks :)

Jan 15 '07 #4
Thank you Stephany!

I tried what you suggested and now on the line containing:

dr.ItemArray = line.ToCharArray()

I get an error messahe stating "Error 1 Value of type '1-dimensional
array of Char' cannot be converted to '1-dimensional array of Object'
because 'Char' is not a reference type."
Stephany Young wrote:
Sorry, you can't do this directly with the Rows.Add method.

You have to do it indirectly, something like:

Dim d As DataTable = New DataTable
Dim line As String = "abcdefg"
For i As Integer = 0 to line.Length - 1
d.Columns.Add(New DataColumn("c" & i.ToString,
Type.GetType("System.Char")))
Next
Dim dr As DataRow = _d.NewRow()
dr.ItemArray = line.ToCharArray()
d.Rows.Add(_dr)
Me.DataGridView1.DataSource = d
"Paulers" <Su*******@gmail.comwrote in message
news:11*********************@l53g2000cwa.googlegro ups.com...
Hello and thanks for your response!

I gave that a try and when I display my DataGridView it shows
System.Char[] in the first col.

Here is what I did

Dim d As DataTable = New DataTable
Dim line As String = "abcdefg"
d.Rows.Add(line.ToCharArray())
Me.DataGridView1.DataSource = d

Stephany Young wrote:
You need to convert the string to an array of characters:

Dim chararray As Char() = MyString.ToCharArray()

and then feed the array of characters to the Rows.Add method:

myDataTable.Rows.Add(chararray)

If you do not need to 'save' the interim result for another purpose then
you
could feed it in directly:

myDataTable.Rows.Add(MyString.ToCharArray())

character
"Paulers" <Su*******@gmail.comwrote in message
news:11**********************@s34g2000cwa.googlegr oups.com...
Hello,

I have a string that I am trying to add each char to a datatable row.

for example if I have a string that looks like "abcdefg", I would like
to break it up into an array of characters so I can do this:

myDataTable.Rows.Add(array())

instead of myDataTable.Rows.Add("a","b","c","d","e","f","g")

You help is greatly appreciated!

thanks :)
Jan 15 '07 #5
Well you have a couple of options:

Dim d As DataTable = New DataTable
Dim line As String = "abcdefg"
For i As Integer = 0 to line.Length - 1
d.Columns.Add(New DataColumn("c" & i.ToString,
Type.GetType("System.Char")))
Next
Dim dr As DataRow = _d.NewRow()
Dim o As Object() = new Object(line.Length -1) {}
For i As Integer = 0 to line.Length - 1
o(_i) = line.Chars(i)
Next
dr.ItemArray = o
d.Rows.Add(_dr)
Me.DataGridView1.DataSource = d

or:

Dim d As DataTable = New DataTable
Dim line As String = "abcdefg"
For i As Integer = 0 to line.Length - 1
d.Columns.Add(New DataColumn("c" & i.ToString,
Type.GetType("System.Char")))
Next
Dim dr As DataRow = _d.NewRow()
For i As Integer = 0 to line.Length - 1
dr(_i) = lone.Chars(i)
Next
d.Rows.Add(_dr)
Me.DataGridView1.DataSource = d

Either way, you need to deal with each character individually.
"Paulers" <Su*******@gmail.comwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...
Thank you Stephany!

I tried what you suggested and now on the line containing:

dr.ItemArray = line.ToCharArray()

I get an error messahe stating "Error 1 Value of type '1-dimensional
array of Char' cannot be converted to '1-dimensional array of Object'
because 'Char' is not a reference type."
Stephany Young wrote:
>Sorry, you can't do this directly with the Rows.Add method.

You have to do it indirectly, something like:

Dim d As DataTable = New DataTable
Dim line As String = "abcdefg"
For i As Integer = 0 to line.Length - 1
d.Columns.Add(New DataColumn("c" & i.ToString,
Type.GetType("System.Char")))
Next
Dim dr As DataRow = _d.NewRow()
dr.ItemArray = line.ToCharArray()
d.Rows.Add(_dr)
Me.DataGridView1.DataSource = d
"Paulers" <Su*******@gmail.comwrote in message
news:11*********************@l53g2000cwa.googlegr oups.com...
Hello and thanks for your response!

I gave that a try and when I display my DataGridView it shows
System.Char[] in the first col.

Here is what I did

Dim d As DataTable = New DataTable
Dim line As String = "abcdefg"
d.Rows.Add(line.ToCharArray())
Me.DataGridView1.DataSource = d

Stephany Young wrote:
You need to convert the string to an array of characters:

Dim chararray As Char() = MyString.ToCharArray()

and then feed the array of characters to the Rows.Add method:

myDataTable.Rows.Add(chararray)

If you do not need to 'save' the interim result for another purpose
then
you
could feed it in directly:

myDataTable.Rows.Add(MyString.ToCharArray())

character
"Paulers" <Su*******@gmail.comwrote in message
news:11**********************@s34g2000cwa.googleg roups.com...
Hello,

I have a string that I am trying to add each char to a datatable
row.

for example if I have a string that looks like "abcdefg", I would
like
to break it up into an array of characters so I can do this:

myDataTable.Rows.Add(array())

instead of myDataTable.Rows.Add("a","b","c","d","e","f","g")

You help is greatly appreciated!

thanks :)


Jan 15 '07 #6
Stephany,

You are great! Thanks a million for your help. I hope some day I am as
knowledgable about vb.net as you are.
Stephany Young wrote:
Well you have a couple of options:

Dim d As DataTable = New DataTable
Dim line As String = "abcdefg"
For i As Integer = 0 to line.Length - 1
d.Columns.Add(New DataColumn("c" & i.ToString,
Type.GetType("System.Char")))
Next
Dim dr As DataRow = _d.NewRow()
Dim o As Object() = new Object(line.Length -1) {}
For i As Integer = 0 to line.Length - 1
o(_i) = line.Chars(i)
Next
dr.ItemArray = o
d.Rows.Add(_dr)
Me.DataGridView1.DataSource = d

or:

Dim d As DataTable = New DataTable
Dim line As String = "abcdefg"
For i As Integer = 0 to line.Length - 1
d.Columns.Add(New DataColumn("c" & i.ToString,
Type.GetType("System.Char")))
Next
Dim dr As DataRow = _d.NewRow()
For i As Integer = 0 to line.Length - 1
dr(_i) = lone.Chars(i)
Next
d.Rows.Add(_dr)
Me.DataGridView1.DataSource = d

Either way, you need to deal with each character individually.
"Paulers" <Su*******@gmail.comwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...
Thank you Stephany!

I tried what you suggested and now on the line containing:

dr.ItemArray = line.ToCharArray()

I get an error messahe stating "Error 1 Value of type '1-dimensional
array of Char' cannot be converted to '1-dimensional array of Object'
because 'Char' is not a reference type."
Stephany Young wrote:
Sorry, you can't do this directly with the Rows.Add method.

You have to do it indirectly, something like:

Dim d As DataTable = New DataTable
Dim line As String = "abcdefg"
For i As Integer = 0 to line.Length - 1
d.Columns.Add(New DataColumn("c" & i.ToString,
Type.GetType("System.Char")))
Next
Dim dr As DataRow = _d.NewRow()
dr.ItemArray = line.ToCharArray()
d.Rows.Add(_dr)
Me.DataGridView1.DataSource = d
"Paulers" <Su*******@gmail.comwrote in message
news:11*********************@l53g2000cwa.googlegro ups.com...
Hello and thanks for your response!

I gave that a try and when I display my DataGridView it shows
System.Char[] in the first col.

Here is what I did

Dim d As DataTable = New DataTable
Dim line As String = "abcdefg"
d.Rows.Add(line.ToCharArray())
Me.DataGridView1.DataSource = d

Stephany Young wrote:
You need to convert the string to an array of characters:

Dim chararray As Char() = MyString.ToCharArray()

and then feed the array of characters to the Rows.Add method:

myDataTable.Rows.Add(chararray)

If you do not need to 'save' the interim result for another purpose
then
you
could feed it in directly:

myDataTable.Rows.Add(MyString.ToCharArray())

character
"Paulers" <Su*******@gmail.comwrote in message
news:11**********************@s34g2000cwa.googlegr oups.com...
Hello,

I have a string that I am trying to add each char to a datatable
row.

for example if I have a string that looks like "abcdefg", I would
like
to break it up into an array of characters so I can do this:

myDataTable.Rows.Add(array())

instead of myDataTable.Rows.Add("a","b","c","d","e","f","g")

You help is greatly appreciated!

thanks :)
Jan 15 '07 #7

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

Similar topics

14
by: Mr.Clean | last post by:
I have a string. I'd like to take this string and make each char change until it gets to another char at the same position of the string. Example: Original String: " NEW YORK " Final...
4
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where...
17
by: Chad Myers | last post by:
I've been perf testing an application of mine and I've noticed that there are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String instances being created. I've done some...
7
by: Eric | last post by:
Hi All, I need to XOR two same-length Strings against each other. I'm assuming that, in order to do so, I'll need to convert each String to a BitArray. Thus, my question is this: is there an...
15
by: Daren | last post by:
Hi, I need to be able to split large string variables into an array of lines, each line can be no longer than 70 chars. The string variables are text, so I would additionally like the lines...
6
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or...
17
by: Christoph Scholtes | last post by:
Hi, I have two questions about the following code snippet. I am trying to read in a series of strings and save them to character arrays. Since I dont know how long my string is going to be (and...
16
by: Hugh Janus | last post by:
Hi all, I am using the below functions in order to convert strings to bytes and vice versa. I totally ans shamefully stole these functions from this group btw! Anyway, they work great but as...
38
by: ssecorp | last post by:
char* reverse(char* str) { int length = strlen(str); char* acc; int i; for (i=0; i<=length-1; i++){ acc = str; } return acc; }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.