473,396 Members | 1,895 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 arrays

i have a string and want to split it at the spaces so i used the following code from the microsoft site:

Expand|Select|Wrap|Line Numbers
  1. Dim TestString As String = "apple    pear banana  "
  2. Dim TestArray() As String = Split(TestString)
  3. ' TestArray holds {"apple", "", "", "", "pear", "banana", "", ""}
  4. Dim LastNonEmpty As Integer = -1
  5. For i As Integer = 0 To TestArray.Length - 1
  6.     If TestArray(i) <> "" Then
  7.         LastNonEmpty += 1
  8.         TestArray(LastNonEmpty) = TestArray(i)
  9.     End If
  10. Next
  11. ReDim Preserve TestArray(LastNonEmpty)
  12. ' TestArray now holds {"apple", "pear", "banana"}
  13.  
i m using visual basic 6.0. the variables cudnt be initialized where they were difined so i manipulated the code as

Expand|Select|Wrap|Line Numbers
  1. Dim TestString As String
  2. TestString = "apple    pear banana  "
  3. Dim TestArray() As String
  4. TestArray() = Split(TestString)
  5. ' TestArray holds {"apple", "", "", "", "pear", "banana", "", ""}
  6. Dim LastNonEmpty As Integer
  7. Dim i As Integer
  8. LastNonEmpty = -1
  9. For i = 0 To TestArray.Length - 1               'THE ERROR LINE
  10.     If TestArray(i) <> "" Then
  11.         LastNonEmpty = LastNonEmpty + 1
  12.         TestArray(LastNonEmpty) = TestArray(i)
  13.         MsgBox TestArray(LastNonEmpty)
  14.     End If
  15. Next
  16. ReDim Preserve TestArray(LastNonEmpty)
  17. ' TestArray now holds {"apple", "pear", "banana"}
  18.  
y does this happen?? and it still shows invalid wualifier for TestArray.Length..is there any other way to find the length so dat we cud run the loop ftill dat value only???? i did try len(TestArray) and GetLength(TestArray) but to no avail
Jul 16 '07 #1
6 2449
yzlin04
18
maybe that code is only for VB.net
because i try to run the code (from microsoft), with a bit changes by add a listbox (ListBox1) into the form:

Dim TestString As String = "apple pear banana "
Dim TestArray() As String = Split(TestString)
' TestArray holds {"apple", "", "", "", "pear", "banana", "", ""}
Dim LastNonEmpty As Integer = -1
For i As Integer = 0 To TestArray.Length - 1
If TestArray(i) <> "" Then
LastNonEmpty += 1
TestArray(LastNonEmpty) = TestArray(i)
ListBox1.items.add(TestArray(i))
End If
Next
ReDim Preserve TestArray(LastNonEmpty)
' TestArray now holds {"apple", "pear", "banana"}

it works







i have a string and want to split it at the spaces so i used the following code from the microsoft site:

Expand|Select|Wrap|Line Numbers
  1. Dim TestString As String = "apple    pear banana  "
  2. Dim TestArray() As String = Split(TestString)
  3. ' TestArray holds {"apple", "", "", "", "pear", "banana", "", ""}
  4. Dim LastNonEmpty As Integer = -1
  5. For i As Integer = 0 To TestArray.Length - 1
  6.     If TestArray(i) <> "" Then
  7.         LastNonEmpty += 1
  8.         TestArray(LastNonEmpty) = TestArray(i)
  9.     End If
  10. Next
  11. ReDim Preserve TestArray(LastNonEmpty)
  12. ' TestArray now holds {"apple", "pear", "banana"}
  13.  
i m using visual basic 6.0. the variables cudnt be initialized where they were difined so i manipulated the code as

Expand|Select|Wrap|Line Numbers
  1. Dim TestString As String
  2. TestString = "apple    pear banana  "
  3. Dim TestArray() As String
  4. TestArray() = Split(TestString)
  5. ' TestArray holds {"apple", "", "", "", "pear", "banana", "", ""}
  6. Dim LastNonEmpty As Integer
  7. Dim i As Integer
  8. LastNonEmpty = -1
  9. For i = 0 To TestArray.Length - 1               'THE ERROR LINE
  10.     If TestArray(i) <> "" Then
  11.         LastNonEmpty = LastNonEmpty + 1
  12.         TestArray(LastNonEmpty) = TestArray(i)
  13.         MsgBox TestArray(LastNonEmpty)
  14.     End If
  15. Next
  16. ReDim Preserve TestArray(LastNonEmpty)
  17. ' TestArray now holds {"apple", "pear", "banana"}
  18.  
y does this happen?? and it still shows invalid wualifier for TestArray.Length..is there any other way to find the length so dat we cud run the loop ftill dat value only???? i did try len(TestArray) and GetLength(TestArray) but to no avail
Jul 16 '07 #2
it is not working . i am working in vb 6.0 and i havent done vb.net so i cant comment on dat. the code is having same errors:
1) it shows TestArray as invalid qualifier
2)the variables cannot be iinitialized where they r defined
Jul 16 '07 #3
Killer42
8,435 Expert 8TB
In VB6, an array doesn't have attributes like .Length - that's from other languages (like Java, or its close cousin, VB.Net). What you need to use is the Ubound() function.
Jul 17 '07 #4
thnks a lot ...can u tell me any place or link where we can search funtions by the job they do and not by their names???lest i wud have found ubound() myself
Jul 17 '07 #5
Killer42
8,435 Expert 8TB
thnks a lot ...can u tell me any place or link where we can search funtions by the job they do and not by their names???lest i wud have found ubound() myself
I think the MSDN website has some such reference, but it might take a while to track down the right place to browse. There's a lot of information there.

Also, I've just tried a Google search on "vb functions by category" and there were a few hits that looked as though they might be relevant. I didn't take the time to look at more than one or two, though.

Perhaps we could start such a list here, in our Articles section. (And we could add info on how to achieve similar things in VB and VB.Net)

Keep in mind, a bit of creative searching will often find what you want. For example, if you were to search TheScripts for something like "VB ARRAY SIZE" you would probably find some relevant entries, but you may need to spend some time reading through the discussions.
Jul 17 '07 #6
I think the MSDN website has some such reference, but it might take a while to track down the right place to browse. There's a lot of information there.

Also, I've just tried a Google search on "vb functions by category" and there were a few hits that looked as though they might be relevant. I didn't take the time to look at more than one or two, though.

Perhaps we could start such a list here, in our Articles section. (And we could add info on how to achieve similar things in VB and VB.Net)

Keep in mind, a bit of creative searching will often find what you want. For example, if you were to search TheScripts for something like "VB ARRAY SIZE" you would probably find some relevant entries, but you may need to spend some time reading through the discussions.


thnks a lot for replying...,
Jul 20 '07 #7

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

Similar topics

3
by: Java script Dude | last post by:
Some programmers prefer to stay with native level data structures such as string arrays instead of using Object based data structures such as ArrayList. From and efficiency point of view. Are...
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 *...
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...
37
by: jortizclaver | last post by:
Hi, I'm about to develop a new framework for my corporative applications and my first decision point is what kind of strings to use: std::string or classical C char*. Performance in my system...
18
by: greenflame | last post by:
I want to make a function that does the following. I will call it thefunc for short. '||Char>>' I tried the following def thefunc(s): s = "||" + s + ">>"
14
by: rohitpatel9999 | last post by:
Hi While developing any software, developer need to think about it's possible enhancement for international usage and considering UNICODE. I have read many nice articles/items in advanced C++...
9
by: jerry.upstatenyguy | last post by:
I am really stuck on this. I am trying to write a string array containing a "word" and a "definition" to a class called Entry. Ultimately this will end up in another class called dictionary. No,...
3
by: SneakyElf | last post by:
i am very green with c++ so i get stuck on very simple things anyway, i need to write a program that would read data from file (containing names of tv shows and their networks) one line at a time...
3
by: shapper | last post by:
Hello, I have two arrays of strings, s1 and s2: s1 = "london, lisbon, paris, newyork" s2 = "lisbon, yellow, France" s2 will have only one item included in s1.
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: 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
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.