473,763 Members | 5,610 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String array problem

Hi,

I'm trying to create an array containing the entire contents of a text file
and delimit the elements using vbCrLf.

The text file is like this....

-text1
-text2
-text3
etc...

I can read the file in like this...
Dim TEST As New StreamReader("C :\test.txt")
Dim line As String = TEST.ReadLine()
While Not line = Nothing
Console.WriteLi ne(line)
line = TEST.ReadLine()
End While

What i'm trying to do is load each element of the text file, in this case
each line (-text1, -text2, -text3 etc..) into an array which I can later use
to compare another string (let's say, strA) with and remove, if found, any
occurances of an array element from strA. So for example, if strA contains
"this is a string -line2" then the "-text2" part of is removed from strA
using strA = strA.Replace(Wh atever match was found, "")

All I have at the moment is how to read the file in, as i wrote above, so
any help with the creation of the array and the comparing against another
string is much appreciated.

Cheers,
Paul
Nov 21 '05 #1
5 1231
Try something like:

Dim _sr As StreamReader = New StreamReader("C :\test.txt")

Dim _ss() As String = _sr.ReadToEnd() .Replace(Contro lChars.Lf,
String.Empty).S plit(ControlCha rs.Cr)

_sr.Close()

For _i As Integer = 0 to _i.Length - 1
Dim _p As Integer = _strA.IndexOf(_ ss(_i))
If p > -1 Then _strA = _strA.Remove(_p , _ss(_i).Length)
Next
"Paul" <me@home.com> wrote in message
news:fN******** ************@pi pex.net...
Hi,

I'm trying to create an array containing the entire contents of a text
file and delimit the elements using vbCrLf.

The text file is like this....

-text1
-text2
-text3
etc...

I can read the file in like this...
Dim TEST As New StreamReader("C :\test.txt")
Dim line As String = TEST.ReadLine()
While Not line = Nothing
Console.WriteLi ne(line)
line = TEST.ReadLine()
End While

What i'm trying to do is load each element of the text file, in this case
each line (-text1, -text2, -text3 etc..) into an array which I can later
use to compare another string (let's say, strA) with and remove, if found,
any occurances of an array element from strA. So for example, if strA
contains "this is a string -line2" then the "-text2" part of is removed
from strA using strA = strA.Replace(Wh atever match was found, "")

All I have at the moment is how to read the file in, as i wrote above, so
any help with the creation of the array and the comparing against another
string is much appreciated.

Cheers,
Paul

Nov 21 '05 #2
Hey, thanks for the reply Stephany.

I'm getting an error on your code on this line though.
For _i As Integer = 0 To _i.Length - 1
'Length' is not a member of 'Integer'

I changed that to _i.ToString.Len gth -1 and it compiled but only the matches
of the first line of the array are removed.
For example if strA contains -line1 then -line1 is removed but if strA
contains -line2 or anything else the match is not removed.
Thanks,
Paul
"Stephany Young" <noone@localhos t> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Try something like:

Dim _sr As StreamReader = New StreamReader("C :\test.txt")

Dim _ss() As String = _sr.ReadToEnd() .Replace(Contro lChars.Lf,
String.Empty).S plit(ControlCha rs.Cr)

_sr.Close()

For _i As Integer = 0 to _i.Length - 1
Dim _p As Integer = _strA.IndexOf(_ ss(_i))
If p > -1 Then _strA = _strA.Remove(_p , _ss(_i).Length)
Next
"Paul" <me@home.com> wrote in message
news:fN******** ************@pi pex.net...
Hi,

I'm trying to create an array containing the entire contents of a text
file and delimit the elements using vbCrLf.

The text file is like this....

-text1
-text2
-text3
etc...

I can read the file in like this...
Dim TEST As New StreamReader("C :\test.txt")
Dim line As String = TEST.ReadLine()
While Not line = Nothing
Console.WriteLi ne(line)
line = TEST.ReadLine()
End While

What i'm trying to do is load each element of the text file, in this case
each line (-text1, -text2, -text3 etc..) into an array which I can later
use to compare another string (let's say, strA) with and remove, if
found, any occurances of an array element from strA. So for example, if
strA contains "this is a string -line2" then the "-text2" part of is
removed from strA using strA = strA.Replace(Wh atever match was found, "")

All I have at the moment is how to read the file in, as i wrote above,
so any help with the creation of the array and the comparing against
another string is much appreciated.

Cheers,
Paul


Nov 21 '05 #3
Should have been:

For _i As Integer = 0 To _ss.Length - 1
"Paul" <me@home.com> wrote in message
news:es******** ************@pi pex.net...
Hey, thanks for the reply Stephany.

I'm getting an error on your code on this line though.
For _i As Integer = 0 To _i.Length - 1
'Length' is not a member of 'Integer'

I changed that to _i.ToString.Len gth -1 and it compiled but only the
matches of the first line of the array are removed.
For example if strA contains -line1 then -line1 is removed but if strA
contains -line2 or anything else the match is not removed.
Thanks,
Paul
"Stephany Young" <noone@localhos t> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Try something like:

Dim _sr As StreamReader = New StreamReader("C :\test.txt")

Dim _ss() As String = _sr.ReadToEnd() .Replace(Contro lChars.Lf,
String.Empty).S plit(ControlCha rs.Cr)

_sr.Close()

For _i As Integer = 0 to _i.Length - 1
Dim _p As Integer = _strA.IndexOf(_ ss(_i))
If p > -1 Then _strA = _strA.Remove(_p , _ss(_i).Length)
Next
"Paul" <me@home.com> wrote in message
news:fN******** ************@pi pex.net...
Hi,

I'm trying to create an array containing the entire contents of a text
file and delimit the elements using vbCrLf.

The text file is like this....

-text1
-text2
-text3
etc...

I can read the file in like this...
Dim TEST As New StreamReader("C :\test.txt")
Dim line As String = TEST.ReadLine()
While Not line = Nothing
Console.WriteLi ne(line)
line = TEST.ReadLine()
End While

What i'm trying to do is load each element of the text file, in this
case each line (-text1, -text2, -text3 etc..) into an array which I can
later use to compare another string (let's say, strA) with and remove,
if found, any occurances of an array element from strA. So for example,
if strA contains "this is a string -line2" then the "-text2" part of is
removed from strA using strA = strA.Replace(Wh atever match was found,
"")

All I have at the moment is how to read the file in, as i wrote above,
so any help with the creation of the array and the comparing against
another string is much appreciated.

Cheers,
Paul



Nov 21 '05 #4
Thanks Stephany thats fixed it!

Cheers,
Paul

"Stephany Young" <noone@localhos t> wrote in message
news:eC******** ******@TK2MSFTN GP12.phx.gbl...
Should have been:

For _i As Integer = 0 To _ss.Length - 1
"Paul" <me@home.com> wrote in message
news:es******** ************@pi pex.net...
Hey, thanks for the reply Stephany.

I'm getting an error on your code on this line though.
For _i As Integer = 0 To _i.Length - 1
'Length' is not a member of 'Integer'

I changed that to _i.ToString.Len gth -1 and it compiled but only the
matches of the first line of the array are removed.
For example if strA contains -line1 then -line1 is removed but if strA
contains -line2 or anything else the match is not removed.
Thanks,
Paul
"Stephany Young" <noone@localhos t> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Try something like:

Dim _sr As StreamReader = New StreamReader("C :\test.txt")

Dim _ss() As String = _sr.ReadToEnd() .Replace(Contro lChars.Lf,
String.Empty).S plit(ControlCha rs.Cr)

_sr.Close()

For _i As Integer = 0 to _i.Length - 1
Dim _p As Integer = _strA.IndexOf(_ ss(_i))
If p > -1 Then _strA = _strA.Remove(_p , _ss(_i).Length)
Next
"Paul" <me@home.com> wrote in message
news:fN******** ************@pi pex.net...
Hi,

I'm trying to create an array containing the entire contents of a text
file and delimit the elements using vbCrLf.

The text file is like this....

-text1
-text2
-text3
etc...

I can read the file in like this...
Dim TEST As New StreamReader("C :\test.txt")
Dim line As String = TEST.ReadLine()
While Not line = Nothing
Console.WriteLi ne(line)
line = TEST.ReadLine()
End While

What i'm trying to do is load each element of the text file, in this
case each line (-text1, -text2, -text3 etc..) into an array which I can
later use to compare another string (let's say, strA) with and remove,
if found, any occurances of an array element from strA. So for
example, if strA contains "this is a string -line2" then the "-text2"
part of is removed from strA using strA = strA.Replace(Wh atever match
was found, "")

All I have at the moment is how to read the file in, as i wrote above,
so any help with the creation of the array and the comparing against
another string is much appreciated.

Cheers,
Paul



Nov 21 '05 #5
"Paul" <me@home.com> wrote in message
news:fN******** ************@pi pex.net...
I'm trying to create an array containing the entire contents of a text file and delimit the elements using vbCrLf.


Read the entire file into a String ([StreamReader].ReadToEnd),
then use

Imports Microsoft.Visua lBasic
. . .
<array> = [Strings].Split( sFiledata, vbCrLf )

to break it up into lines.

Beware [String].Split(), which /only/ supports single-character delimiters.

HTH,
Phill W.
Nov 21 '05 #6

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

Similar topics

10
488
by: Danny | last post by:
HI again Is there a nifty function in access that will: 1. return the amount of occurances of a small string within a larger string? this<br>is<br>a<br>test would return 3 for <br>
7
4361
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 type of "const char *". Right? But why does the compiler I am using allow s to be modified, instead of generating compile error?
4
8823
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 a * occurs in the string). This split function should allocate a 2D array of chars and put the split results in different rows. The listing below shows how I started to work on this. To keep the program simple and help focus the program the...
6
10226
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that the data converted from the byte array into a string , is not what i expect. example: - the data returned from the socket is (byte array) "Usuario Sin Atribuciones Para Esta Función"
17
4667
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 analysis and I'm led to believe (but can't yet quantitatively establish as fact) that the two basic culprits are a lot of calls to: 1.) if( someString.ToLower() == "somestring" ) and
11
17653
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 s(i)=new string(test) Above line gives - error implicit conversion string to 1-dim array of
6
1556
by: MackS | last post by:
Hello everyone I am faced with the following problem. For the first time I've asked myself "might this actually be easier to code in C rather than in python?", and I am not looking at device drivers. : ) This program is meant to process relatively long strings (10-20 MB) by selectively modifying small chunks one at a time. Eg, it locates approx. 1000-2000 characters and modifies them. Currently I was doing this using a string object...
9
1939
by: Ben | last post by:
Hello, I'm not a developper, so sorry if it's a stupid question... I'm trying to develop an application in vb.net and I have the following problem: I have some information in an array: sdist(i). The information is a string. When I run the application, I don"t have problem for compilation but during te execution, I have the error Cast from type 'Object()' to type 'String' is not valid on the line: sdistinguishedname = Sdist(i). Or...
4
11231
by: daroman | last post by:
Hi Guys, i've problem with my small C++ programm. I've just small template class which represetns a array, everything works fine up to combination with std::string. I did tried it with M$ VC++ and with GCC (Cygwin and Linux) and my problem is when i try do this int main(int argc, char **argv) { array<std::stringa(10); a = "Huhuhu"; <--- with gcc i got a crash !
2
5895
by: Assimalyst | last post by:
Hi I have a Dictionary<string, List<string>>, which i have successfully filled. My problem is I need to create a filter expression using all possible permutations of its contents. i.e. the dictionary essentially creates the following array: Key Value
0
9563
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9997
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9937
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8821
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7366
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.