Solved

Comparing a string to a line of text in a text file

Posted on 2012-04-12
4
196 Views
Last Modified: 2012-04-17
I currently have a value (strString) that may be something like this:

mwmiller78ANDsons

I want to search a text file to see if there is the same value but with spaces

i.e. mwmiller78 and sons

If the program finds such a value, it needs to replace strString with the new found value. If it locates such a value, the cycle will end otherwise it will end at EOF.

How would I do this?
TIA
0
Comment
Question by:mwmiller78
  • 2
4 Comments
 
LVL 14

Expert Comment

by:binaryevo
ID: 37839389
Take the string you wish to compare ( IE:  a line of text from the text file ) and something like this:

Dim newString as String = myComparingString.Replace("mwmiller78ANDsons", "new string value")

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37839438
Try following

For each Line As String in IO.Files.ReadAllLines("path")
     if Line.Contains(" " & strString & " ") Then
        'Not sure what you mean by [i]If the program finds such a value, it needs to replace strString with the new found value. [/i]
     End If
Next

Open in new window

0
 

Accepted Solution

by:
mwmiller78 earned 0 total points
ID: 37839604
Got it. Here's what I meant. (Can obviously be simplified...my rough draft)

    Public Function FixSpacing(ByVal fs As String)
        Using reader As New System.IO.StreamReader(strTextFile2)
            While Not reader.EndOfStream
                Dim fsLine As String = reader.ReadLine()
                Dim fsLineRem As String = fsLine.ToString.Replace(" ", "")
                If fsLineRem = fs.Trim Then
                    fs = fsLine.ToString
                    Exit While
                End If
            End While
        End Using
        Return fs
    End Function

Open in new window

0
 

Author Closing Comment

by:mwmiller78
ID: 37854966
Figured it out myself
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now