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

String into an array

Hello all,
I'm trying to do a small application that has this string as an imput "11010" and my goal is to divide the string and load it into an array in this way:
[1][11][110][11010]
The code that I came up with is this:

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2. Dim prefixes(10000) As String
  3. Dim s As String
  4. Dim count As Integer
  5. Dim j As Integer
  6. Dim pre_lenght As Integer
  7. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  8.     TextBox1.Text = "11010"
  9.     s = TextBox1.Text
  10.     pre_lenght = TextBox1.TextLength
  11.     j = pre_lenght
  12.     While j > 0
  13.         For Me.count = 0 To count = pre_lenght
  14.             prefixes(Me.count) = s.Substring(pre_lenght - j)
  15.             j = j - 1
  16.         Next
  17.     End While
  18.     Label1.Text = j
  19.     Label2.Text = pre_lenght
  20.     Label3.Text = prefixes(0)
  21. End Sub
  22. End Class
For some reason it is just storing information in the position 0 of prefixes() and not in any other position,
If someone have any idea of how to solve this problem please let me know.
Thanks.
Daniel.
Feb 6 '08 #1
7 1480
VBWheaties
145 100+
Hello all,
I'm trying to do a small application that has this string as an imput "11010" and my goal is to divide the string and load it into an array in this way:
[1][11][110][11010]
The code that I came up with is this:

Public Class Form1
Dim prefixes(10000) As String
Dim s As String
Dim count As Integer
Dim j As Integer
Dim pre_lenght As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = "11010"
s = TextBox1.Text
pre_lenght = TextBox1.TextLength
j = pre_lenght
While j > 0
For Me.count = 0 To count = pre_lenght
prefixes(Me.count) = s.Substring(pre_lenght - j)
j = j - 1
Next
End While
Label1.Text = j
Label2.Text = pre_lenght
Label3.Text = prefixes(0)
End Sub
End Class

for some reason it is just storing information in the position 0 of prefixes() and not in any other position,
If someone have any idea of how to solve this problem please let me know.
Thanks.
Daniel.
likely your culprit:

Expand|Select|Wrap|Line Numbers
  1. For Me.count = 0 To count = pre_lenght
  2.  
Feb 6 '08 #2
Do you want to store [1101] as well?

Expand|Select|Wrap|Line Numbers
  1. ' VBA
  2.  
  3. Sub Test()
  4.    Dim curr_line As String, i As Integer
  5.  
  6.    curr_line = "11010"
  7.  
  8.    For i = 1 To Len(curr_line)
  9.       Debug.Print Mid(curr_line, 1, i)
  10.    Next i
  11. End Sub
Feb 7 '08 #3
kadghar
1,295 Expert 1GB
wouldnt it be easier with something like:

Expand|Select|Wrap|Line Numbers
  1. dim Str1 as string = "11010"
  2. dim Arr() as string
  3. dim i as long
  4. redim arr(1 to len(str1))
  5. for i = 1 to len(str1)
  6.     arr(i) = left(str1,i)
  7. next
HTH
Feb 7 '08 #4
Killer42
8,435 Expert 8TB
Sorry kadghar, no Left() function any more, remember? Bummer.

Idazaa1 would need to use the substring one instead.
Feb 8 '08 #5
kadghar
1,295 Expert 1GB
Sorry kadghar, no Left() function any more, remember? Bummer.

Idazaa1 would need to use the substring one instead.
lol

sorry, instead of left(string,integer)

you can always use mid(string, 1, integer)

happy now?
Feb 8 '08 #6
Killer42
8,435 Expert 8TB
you can always use mid(string, 1, integer)

happy now?
Not really. That's VB6. Don't think it'll work in the version under discussion. :P
Feb 8 '08 #7
kadghar
1,295 Expert 1GB
Not really. That's VB6. Don't think it'll work in the version under discussion. :P
that's true, i forgot MID wasnt good anymore. It'll take time till i get used to Substring

Then instead of Left(string, length), it should be string.substring(1,length), right?

=( it's like learning to walk again.
Feb 8 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Don Starr | last post by:
When applied to a string literal, is the sizeof operator supposed to return the size of the string (including nul), or the size of a pointer? For example, assuming a char is 1 byte and a char *...
7
by: al | last post by:
char s = "This string literal"; or char *s= "This string literal"; Both define a string literal. Both suppose to be read-only and not to be modified according to Standard. And both have...
4
by: songkv | last post by:
Hi, I am trying to reassign an array of char to a string literal by calling a function. In the function I use pointer-to-pointer since I want to reassign the "string array pointer" to the string...
22
by: spike | last post by:
How do i reset a string? I just want to empty it som that it does not contain any characters Say it contains "hello world" at the time... I want it to contain "". Nothing that is.. Thanx
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...
14
by: Bob | last post by:
I have a function that takes in a list of IDs (hundreds) as input parameter and needs to pass the data to another step as a comma delimited string. The source can easily create this list of IDs in...
8
by: Jeff Johnson | last post by:
Hi, I've begun converting an ASP site over to .NET and I'm a novice at both the new platform as well as C#. I have a COM+ object that returns a string array when it is called. The size of...
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...
11
by: Zordiac | last post by:
How do I dynamically populate a string array? I hope there is something obvious that I'm missing here Option Strict On dim s() as string dim sTmp as string = "test" dim i as integer ...
14
by: Shhnwz.a | last post by:
Hi, I am in confusion regarding jargons. When it is technically correct to say.. String or Character Array.in c. just give me your perspectives in this issue. Thanx in Advance.
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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
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,...

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.