Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP6 Using strtran with wildcards
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00429940
Message ID:
00430134
Views:
14
Hi Ed,

I'm trying to fix a csv file produced from an outlook export. Outlook has a nasty habit of including newline characters in the middle of fields (like the notes field), even when exporting to CSV. The end result is something like:
"First Line","This line should remain unchanged"
"Second Line","This one
should change from 3 lines
to one"
What I want the csv file to look like is
"First Line","This line should remain unchanged"
"Second Line","This one should change from 3 lines to one"
To this end I've tried the following:
local lcInFile, lcOutfile, loReg
lcInFile = filetostr(getfile('txt'))

loReg = create('vbscript.regexp')
with loReg
  .Global = .t.
  .IgnoreCase = .t.
  .Pattern = '[^"]\n'
  lcOutFile = .Replace(lcInFile, ' ')
endwith

strtofile(lcOutFile, getfile('txt'))
in the hope that I'll match all newlines not immediately preceeded by a quote character with a space character. Unfortunately, I'm also replacing the newline characters that are preceeded by a quote character, so the end result is
"First Line","This line should remain unchanged" "Second Line","This one should change from 3 lines to one"
I'm obviously doing something wrong with the pattern, but I can't figure out what.

Any help would be greatly appreciated.

Cheers,

Andrew

>
oReg=CREATEOBJ('VBScript.RegExp')
>oReg.Global = .T.  && apply to all occurances
>oReg.IgnoreCase = .T.  && case-insensitive
>oReg.Pattern = '\([^\)]*\)'  && a (, followed by any number of characters, followed by a )
>REPLACE horse_name with oReg.Replace(horse_name,'')
>
>You can use this in a loop - the regular expression remains the same, so you just need the oReg.Replace call on each iteration.
>
>You need WSH version 2.0 or later. 5 whole lines of code. See my sig block for WSH resources.


If we were to introduce Visual FoxBase+, would we be able to work from the dotNet Prompt?


From Top 22 Developer Responses to defects in Software
2. "It’s not a bug, it’s a feature."
1. "I thought I fixed that."


All my FoxTalk and other articles are available on my web site.


Unless specifically identified otherwise, anthing posted here is purely my opinion and may or may not reflect the policies or practices of Microsoft.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform