4 Replies - 4469 Views - Last Post: 29 May 2009 - 07:53 PM Rate Topic: -----

#1 brainfreeze  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-May 09

Parsing a string array

Posted 28 May 2009 - 12:35 PM

I have a string array (strValues()) that holds a large quantity of character data. I need to parse out characters that follow "*PN" and end with "*". I then need to store this data in a datatable so that I can loop through it afterwards and pull out the unique records to be added to an existing dataset. I've been trying to use basic "IndexOf" to get started but it tells me "Overload resolution failed because no accessible 'IndexOf' accepts this number of arguments".

Is there a way to accomplish what I'm trying to do?

Sample data:

MS50*CF3224205*PNineed/thisdata*SD07JAN10*ED21JAN10

Is This A Good Question/Topic? 0
  • +

Replies To: Parsing a string array

#2 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

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

Re: Parsing a string array

Posted 28 May 2009 - 12:43 PM

at least show the code that tries to do the indexof so we can examine it as well as the definition for the strValues. I assume that you can do something simple like loop over the array and print out the individual entries?

is the sample data typical of a FULL record in an array element?
Was This Post Helpful? 0
  • +
  • -

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,412
  • Joined: 29-May 08

Re: Parsing a string array

Posted 28 May 2009 - 01:08 PM

Parsing a text string for values is what regular expression where developed for, think about using one.
Was This Post Helpful? 0
  • +
  • -

#4 Ghostwolf  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 23
  • Joined: 01-May 09

Re: Parsing a string array

Posted 28 May 2009 - 01:41 PM

Based on that data sample, I think I'd use an array:

dim a as integer,arySplit() as string
	arySplit() = Split(inStr,"*")
	for a = 0 to uBound(arySplit())
		if left(arySplit(a),2) = "PN"
			[do whatever needs doing]
		endif
	next a



Of course, this assumes that "PN", in the first two bytes, will always be an indicator of the data you need from that string.
Was This Post Helpful? 0
  • +
  • -

#5 T3hC13h  Icon User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 337
  • Joined: 05-February 08

Re: Parsing a string array

Posted 29 May 2009 - 07:53 PM

Please post your code so we can tell you where your going wrong.

In the mean time compare this to what youve got and see if you can get it working.

		Dim str_Sample As String = "MS50*CF3224205*PNineed/thisdata*SD07JAN10*ED21JAN10"
		'Start of our data
		Dim int_Start As Integer = str_Sample.IndexOf("PN") + 2
		'Get index of first * after the start of our data and subtract our starting index to get the length of our data
		Dim int_Length As Integer = str_Sample.IndexOf("*", int_Start) - int_Start
		'Return our data.
		Dim str_Out As String = str_Sample.Substring(int_Start, int_Length)

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1