Solved

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

Posted on 2012-04-12
4
195 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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 …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

8 Experts available now in Live!

Get 1:1 Help Now