Convert 1-Dim String Array to String

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2009
Posts: 4
Reputation: Darkicon is an unknown quantity at this point 
Solved Threads: 0
Darkicon Darkicon is offline Offline
Newbie Poster

Convert 1-Dim String Array to String

 
0
  #1
21 Days Ago
I'm working on a mass text replacer program because I'm sick of all the 10-day trial ones out there that aren't very good.

The entire program is basically finished (All easy stuff), but now I need to code the actual replace/delete stuff, which I'm stuck on because apparently the way I originally intended to do it is not possible.

The way it works is you load a text file (.txt, .cfg, .ini, .doc, etc.) which opens a StreamReader which writes all the data into a listbox. Then you pick whether you want to replace or delete a string. If you select replace, then you enter the string to search for and in another textbox you enter the string to replace it with.

The way I originally intended to do this was like this:

  1. If o1.Text = "Replace" Then 'The option
  2. Replace(txtfile, str1, a1) 'txtfile is the data, str1 is the string to find and a1 is the replacement
  3. End If

The problem is, I believe this method requires txtfile, str1 and a1 to be strings, but they're all 1-dimensional string arrays, which cannot be converted to strings, or at least I don't know how to convert them.

A friend told me one way I could do this is to open both a StreamReader and StreamWriter and do the replace/delete line by line as they are entered into the memory and write them to a temporary file which is then copied over the original. I can do this kind of, but I still don't know the proper way of doing the actual replace code because the string to find and the string to replace with are still 1-dimensional string arrays rather than strings.

I can't think of any other way to do this, due to I'm not that experienced in VBNet. Any help is greatly appreciated.
Last edited by Darkicon; 21 Days Ago at 12:20 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 464
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven
 
0
  #2
21 Days Ago
Use Aggregate Method.
  1. Dim s() As String = {"AA", "BB", "CC"}
  2. Dim Str As String
  3. Str = s.Aggregate(Function(P, Q) P & " " & Q)
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC