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

Adding character to string

Status
Not open for further replies.

Majaws2

Programmer
Jul 3, 2003
15
US
I have been trying to add an "x" to the begining of a several rows of data. The best I could do is get the x, a carrige return, then the original data.

what I get:
x
1:9:0 2228 56
what I would like:
x1:9:0 2228 56

notice there is about 25 spaces before the first character sometimes this is 24 or 23.

Here is the code I came up with so far, but dazed and confused now.


string holdthis
string srchField[200]
integer chrlen[200]
integer num2
integer Num
integer Count = 0
integer Count2 = 0
string szLine
proc main

Count=0
num=0
num2=0
if fopen 0 "C:\Program Files\symantec\Procomm Plus\Aspect\traffic_fields.txt" READ
while not feof 0
fgets 0 szline
strtok srchField[Count] szline "," 1
strtok holdthis szline "," 1
atoi holdthis chrlen[Count]
Count += 1
endwhile
fclose 0
endif

fopen 1 "C:\Program Files\symantec\Procomm Plus\Aspect\$aaa.txt" CREATE TEXT
if fopen 0 "C:\Program Files\symantec\Procomm Plus\Aspect\701.cap" READ TEXT
while not feof 0
fgets 0 szline
for Count2 = 0 upto Count-1
if strsearch szline srchField[Count2]
strtok holdthis szline " " chrlen[Count2]
strlen holdthis num

if count2 == Count-1
fputs 1 holdthis
else

fwrite 1 holdthis num
fwrite 1 "," 1
endif
endif
endfor

If strsearch szline "Thu "
strtok holdthis szline " " 4
atoi holdthis num2
fputs 1 holdthis
if num2 > 0
fgets 0 szline
fgets 0 szline
fgets 0 szline
fgets 0 szline

while not strsearch szline "# exit"
strlen szline num2
if num2 > 45
fputs 1 "x"
fputs 1 szline
endif
fgets 0 szline

endwhile
endif
endif
endwhile
endif
fclose 0
endproc
 
The "x" is on its own line because it was output to a file using fputs and the TEXT argument was used when opening the output file. The easiest way to workaround this is to use strcat or strfmt to combine two strings (one containing "x", the other being the data in sLine), and then output that one combined string to the text file.


aspect@aspectscripting.com
 
I was able to get that to work for me.. took me a while though.. thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top