473,785 Members | 2,220 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 11650
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
3434
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 never outputs files with tabs. However, in emacs, tab-width's value is 8. Solution:
17
2204
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
2045
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 of my StreamReader but it's always the same...
135
7527
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 situation behind it, and which is proper.
2
2318
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
2927
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 TextWrap and its member functions take an 'expand_tabs' kwarg, but dedent unfortunately does not. ...
35
2724
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 it to the unix system and the interpreter complains that the indentation style is not consistent...
16
10174
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
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9489
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9959
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6744
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4061
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2893
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.