Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search and replace text in CSV file

Status
Not open for further replies.

montypython1

Technical User
Jan 12, 2005
187
US
Greetings,

I am trying to search a "CSV" file to replace specific characters with different characters (ex: replace 'BELLEVUE' with 'AAAAAAAAAA'). I checked the Tek-Tips archives, I found what I was after (thread184-1050184), but have not been able to make it work.

I must be overlooking something ... the code seems rather straightforward (see below):

**********************************************
lcMyString = FILETOSTR('tables\1on1fi quotes.csv')
WAIT WINDOW 'converting file ... please wait' NOWAIT
STRTRAN(lcMyString , 'BELLEVUE' , 'AAAAAAAAAA')
STRTOFILE(lcMyString , 'tables\1on1fi quotes new2.csv')
?lcMyString
**********************************************

FILETOSTR does convert the file to a text string, and STRTOFILE does successfully convert it back to a file, but STRTRAN does NOT find and replace the characters that I have requested.

Any ideas?

Thanks,
Dave
 
[ ]

The arguments in STRTRAN are case-sensitive. Are you sure that "BELLEVUE" is in upper case in the file?

mmerlinn


"Political correctness is the BADGE of a COWARD!"
 
You need to store the STRTRAN result back to the string var. Your code works, but the result of STRTRAN is going nowhere...

Code:
lcMyString = STRTRAN(lcMyString , 'BELLEVUE' , 'AAAAAAAAAA')

Bye, Olaf.
 
[ ]
Olaf is correct. Unless you update lcMyString there is no way it can work. All you are doing is saving the unchanged original string.

Don't know how I missed that.


mmerlinn


"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Steven Raymond
 
Thank you Olaf and Mmerlinn,

Your suggestion worked perfectly!
I knew that it would be something simple that I was omitting.

Thank you both,
Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top