473,574 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

converting tabs into spaces?

p s
hi all
i have a vb6 project, one of the functions is to read in a text file and
place it into an array
problem is, when people use the TAB key in the original file that is read, i
just get the tab code in the string,
what i need is for the TAB to literally become that many SPACES ... the
problem is this
can vary depending on where exactly the TAB key is hit!
i have tried

sOrigString = Replace(sOrigSt ring, vbTab, " ")

but this just puts in one space
of course if someone hits the tab key at the start of the line it will jump
the cursor further than if someone hit it a few characters in (if you know
what i mean!)

can anybody help?

thanks
pete
Jul 17 '05 #1
13 11625
On Tue, 22 Jul 2003 15:15:07 GMT, "p s" <pe***********@ hotmail.com>
wrote:
hi all
i have a vb6 project, one of the functions is to read in a text file and
place it into an array
problem is, when people use the TAB key in the original file that is read, i
just get the tab code in the string,
what i need is for the TAB to literally become that many SPACES ... the
problem is this
can vary depending on where exactly the TAB key is hit!
i have tried

sOrigString = Replace(sOrigSt ring, vbTab, " ")

but this just puts in one space
of course if someone hits the tab key at the start of the line it will jump
the cursor further than if someone hit it a few characters in (if you know
what i mean!)

can anybody help?

thanks
pete


I'm not sure if you can get the tab size programatically without some
fairly complex complex coding. If you know the tab size you could just
use something like
sOrigString = Replace(sOrigSt ring, vbTab, string(nTabSize , " "))

where tabsize is set to 4 or 8 or whatever you tabsize is.
steve
Jul 17 '05 #2
p s

"steve hotmail.com>" <stesrc@<remove .this.antispam. bit> wrote in message
news:vh******** *************** *********@4ax.c om...
On Tue, 22 Jul 2003 15:15:07 GMT, "p s" <pe***********@ hotmail.com>
wrote:
hi all
i have a vb6 project, one of the functions is to read in a text file and
place it into an array
problem is, when people use the TAB key in the original file that is read, ijust get the tab code in the string,
what i need is for the TAB to literally become that many SPACES ... the
problem is this
can vary depending on where exactly the TAB key is hit!
i have tried

sOrigString = Replace(sOrigSt ring, vbTab, " ")

but this just puts in one space
of course if someone hits the tab key at the start of the line it will jumpthe cursor further than if someone hit it a few characters in (if you knowwhat i mean!)

can anybody help?

thanks
pete


I'm not sure if you can get the tab size programatically without some
fairly complex complex coding. If you know the tab size you could just
use something like
sOrigString = Replace(sOrigSt ring, vbTab, string(nTabSize , " "))

where tabsize is set to 4 or 8 or whatever you tabsize is.
steve

thanks steve...
but doesnt the actual amount of spaces change depending on where you are in
the line?
e.g. tab stops are set up every 8th character... tabbing at start of the
line will mean nTabSize =8 , 5 chars in and nTabSize=3
?
cheers
pete
Jul 17 '05 #3
On Tue, 22 Jul 2003 15:43:44 GMT, "p s" <pe***********@ hotmail.com>
wrote:

"steve hotmail.com>" <stesrc@<remove .this.antispam. bit> wrote in message
news:vh******* *************** **********@4ax. com...
On Tue, 22 Jul 2003 15:15:07 GMT, "p s" <pe***********@ hotmail.com>
wrote:
>hi all
>i have a vb6 project, one of the functions is to read in a text file and
>place it into an array
>problem is, when people use the TAB key in the original file that isread, i >just get the tab code in the string,
>what i need is for the TAB to literally become that many SPACES ... the
>problem is this
>can vary depending on where exactly the TAB key is hit!
>i have tried
>
>sOrigString = Replace(sOrigSt ring, vbTab, " ")
>
>but this just puts in one space
>of course if someone hits the tab key at the start of the line it willjump >the cursor further than if someone hit it a few characters in (if youknow >what i mean!)
>
>can anybody help?
>
>thanks
>pete
>


I'm not sure if you can get the tab size programatically without some
fairly complex complex coding. If you know the tab size you could just
use something like
sOrigString = Replace(sOrigSt ring, vbTab, string(nTabSize , " "))

where tabsize is set to 4 or 8 or whatever you tabsize is.
steve

thanks steve...
but doesnt the actual amount of spaces change depending on where you are in
the line?
e.g. tab stops are set up every 8th character... tabbing at start of the
line will mean nTabSize =8 , 5 chars in and nTabSize=3
?
cheers
pete

Yes it does change which is where the complex coding comes in.

Maybe you could read the line up to a tab chr. Then pad out with
spaces up to the next tab position (given a fixed tab size) then
repeat the process until you are finished.

I've done a similar thing building strings but not on strings being
read then converted. I'll dig out the code if you think it might help
steve
Jul 17 '05 #4
p s
> Yes it does change which is where the complex coding comes in.

Maybe you could read the line up to a tab chr. Then pad out with
spaces up to the next tab position (given a fixed tab size) then
repeat the process until you are finished.

I've done a similar thing building strings but not on strings being
read then converted. I'll dig out the code if you think it might help
steve


thanks steve,

i thought i may have to take this aproach... but then wondered if anyone had
already done it as it seems like it should be a common problem
is there a fixed tab size i should look at, out of interest? these are files
created in windows notepad. can i assume a default?

cheers
pete
Jul 17 '05 #5
In general, a TAB doesn't correspond to a fixed number of spaces, or even a
fixed destination column. In ANSI terms, it's a "format effector" rather
than a "graphic character".

However, if you're using the old VDU convention of 8-character TAB settings,
then this might help:

Private Function iNext(iCh As Integer) As Integer
' Returns the next TAB-column position from the current character position
iNext = 8 * ((iCh \ 8) + 1)
End Function

If you have a TAB at character position iCh then you would simply have to
replace it by

Space$(iNext(iC h)-iCh)
Tony

"p s" <pe***********@ hotmail.com> wrote in message
news:%x******** ***********@new s-text.cableinet. net...
hi all
i have a vb6 project, one of the functions is to read in a text file and
place it into an array
problem is, when people use the TAB key in the original file that is read, i just get the tab code in the string,
what i need is for the TAB to literally become that many SPACES ... the
problem is this
can vary depending on where exactly the TAB key is hit!
i have tried

sOrigString = Replace(sOrigSt ring, vbTab, " ")

but this just puts in one space
of course if someone hits the tab key at the start of the line it will jump the cursor further than if someone hit it a few characters in (if you know
what i mean!)

can anybody help?

thanks
pete

Jul 17 '05 #6
Al
why don't you setup a temp table or array with fields
explain.
assuming that your .TXT file is as follow

John Doe Somewhere in Usa New York, NY 10005 555-5555
president
John Doe Somewhere in Usa New York, NY 10005 555-5555
president
John Doe Somewhere in Usa New York, NY 10005 555-5555
president
John Doe Somewhere in Usa New York, NY 10005 555-5555
president
John Doe Somewhere in Usa New York, NY 10005 555-5555
president
'- your text file setting.
There is 16 space starting from "John Doe" to (Somewhere in usa)
There is 30 space starting from "Somewhere in usa" to (New Yok, NY 10005)
There is 20 space starting from "New York, NY 10005" to (555-5555)
There is 8 space starting "555-55555" to (president)
There is 25 space starting from "president" to (blank spaces)

'- Array or TempTable. (Fields)
field1 = Name Text (16)
field2 = Address Text (30)
field3 = CityStaZip Text (20)
field4 = Telephone Text (8)
field5 = Title Text (25)

'- Read the File
OPEN "TEXT FILE" for input as #1
input #1 field1, field2, field3, field4, field5
I hope this is what you are looking for.
Good Luck...!

"p s" <pe***********@ hotmail.com> wrote in message
news:%x******** ***********@new s-text.cableinet. net...
hi all
i have a vb6 project, one of the functions is to read in a text file and
place it into an array
problem is, when people use the TAB key in the original file that is read, i just get the tab code in the string,
what i need is for the TAB to literally become that many SPACES ... the
problem is this
can vary depending on where exactly the TAB key is hit!
i have tried

sOrigString = Replace(sOrigSt ring, vbTab, " ")

but this just puts in one space
of course if someone hits the tab key at the start of the line it will jump the cursor further than if someone hit it a few characters in (if you know
what i mean!)

can anybody help?

thanks
pete

Jul 17 '05 #7
Sorry, mixing-up my 1:n and 0:n-1 indexing. Should have been

Private Function iNext(iCh As Integer) As Integer
iNext = 8 * (((iCh - 1) \ 8) + 1) + 1
End Function

Tony

"Tony Proctor" <tony_proctor@a imtechnology_NO SPAM.com> wrote in message
news:e0******** ******@tk2msftn gp13.phx.gbl...
In general, a TAB doesn't correspond to a fixed number of spaces, or even a fixed destination column. In ANSI terms, it's a "format effector" rather
than a "graphic character".

However, if you're using the old VDU convention of 8-character TAB settings, then this might help:

Private Function iNext(iCh As Integer) As Integer
' Returns the next TAB-column position from the current character position
iNext = 8 * ((iCh \ 8) + 1)
End Function

If you have a TAB at character position iCh then you would simply have to
replace it by

Space$(iNext(iC h)-iCh)
Tony

"p s" <pe***********@ hotmail.com> wrote in message
news:%x******** ***********@new s-text.cableinet. net...
hi all
i have a vb6 project, one of the functions is to read in a text file and
place it into an array
problem is, when people use the TAB key in the original file that is read,
i
just get the tab code in the string,
what i need is for the TAB to literally become that many SPACES ... the
problem is this
can vary depending on where exactly the TAB key is hit!
i have tried

sOrigString = Replace(sOrigSt ring, vbTab, " ")

but this just puts in one space
of course if someone hits the tab key at the start of the line it will

jump
the cursor further than if someone hit it a few characters in (if you

know what i mean!)

can anybody help?

thanks
pete


Jul 17 '05 #8
p s
thanks tony, same principle as norms code, exactly what i needed

"Tony Proctor" <tony_proctor@a imtechnology_NO SPAM.com> wrote in message
news:OT******** ******@tk2msftn gp13.phx.gbl...
Sorry, mixing-up my 1:n and 0:n-1 indexing. Should have been

Private Function iNext(iCh As Integer) As Integer
iNext = 8 * (((iCh - 1) \ 8) + 1) + 1
End Function

Tony

"Tony Proctor" <tony_proctor@a imtechnology_NO SPAM.com> wrote in message
news:e0******** ******@tk2msftn gp13.phx.gbl...
In general, a TAB doesn't correspond to a fixed number of spaces, or even
a
fixed destination column. In ANSI terms, it's a "format effector" rather
than a "graphic character".

However, if you're using the old VDU convention of 8-character TAB

settings,
then this might help:

Private Function iNext(iCh As Integer) As Integer
' Returns the next TAB-column position from the current character position iNext = 8 * ((iCh \ 8) + 1)
End Function

If you have a TAB at character position iCh then you would simply have to replace it by

Space$(iNext(iC h)-iCh)
Tony

"p s" <pe***********@ hotmail.com> wrote in message
news:%x******** ***********@new s-text.cableinet. net...
hi all
i have a vb6 project, one of the functions is to read in a text file and place it into an array
problem is, when people use the TAB key in the original file that is

read,
i
just get the tab code in the string,
what i need is for the TAB to literally become that many SPACES ... the problem is this
can vary depending on where exactly the TAB key is hit!
i have tried

sOrigString = Replace(sOrigSt ring, vbTab, " ")

but this just puts in one space
of course if someone hits the tab key at the start of the line it will

jump
the cursor further than if someone hit it a few characters in (if you

know what i mean!)

can anybody help?

thanks
pete



Jul 17 '05 #9
p s
cheers al
problem is my lines are varying ... they are not uniform as in your example
thanks again
pete

"Al" <al*****@mashis pano.com> wrote in message
news:un******** *****@TK2MSFTNG P12.phx.gbl...
why don't you setup a temp table or array with fields
explain.
assuming that your .TXT file is as follow

John Doe Somewhere in Usa New York, NY 10005 555-5555
president
John Doe Somewhere in Usa New York, NY 10005 555-5555
president
John Doe Somewhere in Usa New York, NY 10005 555-5555
president
John Doe Somewhere in Usa New York, NY 10005 555-5555
president
John Doe Somewhere in Usa New York, NY 10005 555-5555
president
'- your text file setting.
There is 16 space starting from "John Doe" to (Somewhere in usa)
There is 30 space starting from "Somewhere in usa" to (New Yok, NY 10005)
There is 20 space starting from "New York, NY 10005" to (555-5555)
There is 8 space starting "555-55555" to (president)
There is 25 space starting from "president" to (blank spaces)

'- Array or TempTable. (Fields)
field1 = Name Text (16)
field2 = Address Text (30)
field3 = CityStaZip Text (20)
field4 = Telephone Text (8)
field5 = Title Text (25)

'- Read the File
OPEN "TEXT FILE" for input as #1
input #1 field1, field2, field3, field4, field5
I hope this is what you are looking for.
Good Luck...!

"p s" <pe***********@ hotmail.com> wrote in message
news:%x******** ***********@new s-text.cableinet. net...
hi all
i have a vb6 project, one of the functions is to read in a text file and
place it into an array
problem is, when people use the TAB key in the original file that is read,
i
just get the tab code in the string,
what i need is for the TAB to literally become that many SPACES ... the
problem is this
can vary depending on where exactly the TAB key is hit!
i have tried

sOrigString = Replace(sOrigSt ring, vbTab, " ")

but this just puts in one space
of course if someone hits the tab key at the start of the line it will

jump
the cursor further than if someone hit it a few characters in (if you

know what i mean!)

can anybody help?

thanks
pete


Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3419
by: Dan Jacobson | last post by:
In wdg-html-reference/html40/block/pre.html there is no mention about how ASCII tabs (^I) are to be rendered. I suppose all bets are off? Wait, my docs go thru html-tidy first, and it says tab-size: number Sets the number of columns between successive tab stops. The default is 4. It is used to map tabs to spaces when reading files. Tidy...
17
2189
by: bearophileHUGS | last post by:
Hello, I know this topic was discussed a *lot* in the past, sorry if it bores you... >From the Daily Python-URL I've seen this interesting Floating Point Benchmark: http://www.fourmilab.ch/fourmilog/archives/2005-08/000567.html This is the source pack: http://www.fourmilab.ch/fbench/fbench.zip
1
2037
by: Kevin Auch | last post by:
Hi, I'm working on a little application which analyse source code file from VS.NET. But I'm in front of a big problem. The source generated by VS.NET is automatically "indented", but when I analyse these lines I can't remove the tabs or the spaces at the beginning of the line because it's not spaces or tabs. I tried to change the encoding...
135
7426
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about which is better. It has become what's known as “religious war” — a heated fight over trivia. In this essay, i like to explain what is the...
2
2308
by: Laurence | last post by:
In VS.2005, using VB.NET My editor is behaving strangely. If I press the tab key, the line moves over the appropriate number of spaces. When I click on another line, the line that I had tab'd on moves over more spaces. I have changed the tab and insert, but it doesn't seem to work.
15
2899
by: Tom Plunket | last post by:
The documentation for dedent says, "Remove any whitespace than can be uniformly removed from the left of every line in `text`", yet I'm finding that it's also modifying the '\t' characters, which is highly undesirable in my application. Is there any way to stop it from doing this, or alternatively, to put those tabs back in? I see that...
35
2686
by: Ben | last post by:
Hi, I have a python script on a unix system that runs fine. I have a python script on a windows system that runs fine. Both use tabs to indent sections of the code. I now want to run them on the same system, actually in the same script by combining bits and pieces. But whatever I try my windows tabs get converted to spaces when I transfer...
16
10045
by: Alan Isaac | last post by:
I am brand new to pylint. As a tab user, I want the tabs warning turned off. How? Larger question: where is the config file format documented? Thanks, Alan Isaac
0
7737
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8075
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7827
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5632
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5316
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1356
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1072
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.