array prob

spliting array

Page 1 of 1

9 Replies - 656 Views - Last Post: 01 December 2009 - 03:18 PM Rate Topic: ***-- 2 Votes

#1 cindrellacool  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 04-October 09

array prob

Post icon  Posted 30 November 2009 - 09:52 AM

I want to read tagged file then split them at "NN" word and show that file with its indices
Here is my code:

 
Imports System.IO
Module Module1

	Sub Main()

		Dim d As FileStream = New FileStream("f:\DVD_Tagged.txt", FileMode.Open, FileAccess.Read)
		Dim c As StreamReader = New StreamReader(d)
		Dim z() As String

		Dim index As Integer = 0
		Do Until c.EndOfStream = True
			ReDim Preserve z(index)

			z(index) = c.ReadLine()
			index += 1
		Loop
		
		c.Close()
		d.Close()


		Dim i As FileStream = New FileStream("f:\my.txt", FileMode.Append, FileAccess.Write)
		Dim g As StreamWriter = New StreamWriter(i)
		Dim j As Integer
		Dim array() As String
		For j = 0 To z.GetUpperBound(0)

			'g.WriteLine(j & " " & z(j))
			array = g.split(z, "NN" & "NG")

			g.WriteLine(array(j))
		Next




		g.Close()
		i.Close()

	End Sub

End Module


giving error that
"'split' is not a member of 'System.IO.StreamWriter'."

Is This A Good Question/Topic? 0
  • +

Replies To: array prob

#2 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: array prob

Posted 30 November 2009 - 09:59 AM

you probably mean
array = z(j).split("NN" & "NG")


Was This Post Helpful? 0
  • +
  • -

#3 cindrellacool  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 04-October 09

Re: array prob

Posted 30 November 2009 - 12:16 PM

View Postmark.bottomley, on 30 Nov, 2009 - 08:59 AM, said:

you probably mean
array = z(j).split("NN" & "NG")


after using ur code program give error on
For j = 0 To z.GetUpperBound(0)


i thnk there is a small prob in this program
Was This Post Helpful? 0
  • +
  • -

#4 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: array prob

Posted 30 November 2009 - 05:27 PM

First, simplify the file reading with
Dim z() As String = System.IO.File.ReadAllLines("<your file name>")


I suspect tha the problem is:
g.WriteLine(array(j))

where j keeps incrementing and I suspect that you want to pick out some particular CONSTANT index like 3.

Also, what error is it giving???
Was This Post Helpful? 0
  • +
  • -

#5 cindrellacool  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 04-October 09

Re: array prob

Posted 01 December 2009 - 01:24 PM

View Postmark.bottomley, on 30 Nov, 2009 - 04:27 PM, said:

First, simplify the file reading with
Dim z() As String = System.IO.File.ReadAllLines("<your file name>")


I suspect tha the problem is:
g.WriteLine(array(j))

where j keeps incrementing and I suspect that you want to pick out some particular CONSTANT index like 3.

Also, what error is it giving???

giving a null reference error @ z.getupperbound
Was This Post Helpful? 0
  • +
  • -

#6 cindrellacool  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 04-October 09

Re: array prob

Posted 01 December 2009 - 01:42 PM

Is there any fault in my codes for reading file?
Was This Post Helpful? 0
  • +
  • -

#7 Matty919  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 83
  • Joined: 10-May 09

Re: array prob

Posted 01 December 2009 - 01:55 PM

I posted in your other thread trying to help, did you look at this?

http://www.dreaminco...topic141673.htm
Was This Post Helpful? 1
  • +
  • -

#8 cindrellacool  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 04-October 09

Re: array prob

Posted 01 December 2009 - 02:38 PM

View PostMatty919, on 1 Dec, 2009 - 12:55 PM, said:

I posted in your other thread trying to help, did you look at this?

http://www.dreaminco...topic141673.htm

ya tht was helpful for me bt nw im trying to split tht file with its indics.
Was This Post Helpful? 0
  • +
  • -

#9 crepitus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 84
  • View blog
  • Posts: 383
  • Joined: 08-September 09

Re: array prob

Posted 01 December 2009 - 03:00 PM

array = z(j).split("NN" & "NG")

is the same as:

array = z(j).split("NNNG")

And the split method has no overload that accepts a String. So, VB.Net helpfully casts the String to a Char and lets it compile.
I had no idea you could cast a String to a Char, but you can, so your line is now the equivalent of:

array = z(j).split("N"c)

What you should do is always put:
Option Strict On 
Option Strict On


at the top of the code file, so that you are not allowed to call methods with incorrectly typed parameters, this will warn you of many problems.

What do you actually want to split on? I think you want to split on both "NN" and "NG" so:

array = z(j).Split(New String() {"NN", "NG"}, StringSplitOptions.RemoveEmptyEntries)

This post has been edited by crepitus: 01 December 2009 - 03:03 PM

Was This Post Helpful? 1
  • +
  • -

#10 cindrellacool  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 04-October 09

Re: array prob

Posted 01 December 2009 - 03:18 PM

i only knw the basic abt the vb.In dis program i want to read tagged files which ve NN or NG tags only

This post has been edited by cindrellacool: 01 December 2009 - 03:21 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1