944,014 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 1760
  • VB.NET RSS
Nov 7th, 2009
0

Convert 1-Dim String Array to String

Expand Post »
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:

VB Syntax (Toggle Plain Text)
  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; Nov 7th, 2009 at 12:20 am.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Darkicon is offline Offline
21 posts
since Jun 2009
Nov 7th, 2009
0
Re: Convert 1-Dim String Array to String
Use Aggregate Method.
VB.NET Syntax (Toggle Plain Text)
  1. Dim s() As String = {"AA", "BB", "CC"}
  2. Dim Str As String
  3. Str = s.Aggregate(Function(P, Q) P & " " & Q)
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Sep 22nd, 2011
0
Re: Convert 1-Dim String Array to String
adatapost - beautiful.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
crashed is offline Offline
1 posts
since Sep 2011

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Saving ListView Items and SubItems
Next Thread in VB.NET Forum Timeline: How to compare two Date values in two different columns of a table





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC