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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TAB DELIMIT COLUMS?

Status
Not open for further replies.

Volkmaniac

Technical User
Mar 19, 2003
104
0
0
US
I took a script off that inserts a tab delimit at the end of every line:

proc main
string sLine, sTemp1, sTemp2, sTemp3
fopen 0 "C:\XXX_031204.txt" READ TEXT
while not feof 0
fgets 0 sLine
strtok sTemp1 sLine "`t" 1
strtok sTemp2 sLine "`t" 1
strtok sTemp3 sLine "`t" 1
endwhile
fclose 0
endproc


Is there a way I'd be able to insert a tab delimit on a space? I'd need to insert the tab delimit after each space so it can import easier into Excel:

CAP1SHZ 123 235359.70 25752.96
CAP1SLZ 17 10008.43 1736.24
CAP1SPZ 15 33892.88 10850.89
CAP1SSZ 44 57950.68 7333.66
A: 199 337211.69 45673.75
 
Is your data going to have just one space between fields, or could it have several spaces between fields? If just one space between fields, then you could use this:

strreplace sVar " " " `t"

to replace all spaces with a space and a tab character in the string sVar.


aspect@aspectscripting.com
 
Thank You. The only problem is that it is placing a tab on every single space in the line, and some of the numbers are multiple spaces apart. Is there anyway it can only insert one tab on the first instance of a space?

 
Probably the easiest way to do it would be to use strlen to get the length of the strength, then loop through character by character using the stgetc command to get the current character. At the same time you are going through the original string, you would be building a new string with the strputc command. If the value read with strgetc is 32 (the ASCII value for a space), then you would want to set a flag indicating you found a space. On the next time through the loop, if the value was not 32 and your flag was set, you would also add a `t to the new string, then the value you had just read.

I'm getting ready to leave work now, but will try to come up with some code later tonight.


aspect@aspectscripting.com
 
Here's a script that I think should do the trick:

proc main
string sLine = "1 2 3 4"
integer iPos
string sNewLine
integer iLoop, iLen
integer iChar
integer iFlag

strlen sLine iLena
for iLoop = 0 upto iLen-1
strgetc sLine iLoop iChar
if iChar == 32
iFlag = 1
strputc sNewLine iPos iChar
else
if iFlag == 1
strputc sNewLine iPos 9
iPos++
strputc sNewLine iPos iChar
iFlag = 0
else
strputc sNewLine iPos iChar
endif
endif
iPos++
endfor
endproc

sNewLine will contain the new script with the tabs.

aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top