Re: How to dedect 4 consecutive space




<elingtse@xxxxxxxxx> wrote in message
news:1136026099.945497.270800@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> HI all,
>
> I need to replace a tab for every 4 consecutive spaces for a statement
> which is included in an array. I've set another index array to mark
> whether the content is space, if the index become 4, if change to tab.
> But it seems hard to go back the previous index to delete the previous
> spaces in a for loop. Could anyone give me some hints ? Thanks a lot.
>
> Statement Example :
>
> s = space
> t = tab
> X = content
>
> sssssssssXXXXXssssssXXXXXX
>
> Expected Solution :
>
> ttsXXXXXtssXXXXXX
> (replace every consecutive 4 space into tab)

But you probably need to do more than that for a real "tabify".
Consider:

stXXX, sstXXX, or ssstXXX all become tXXX
and probably sXXX becomes tXXX
XsssX becomes XtX, XXssX becomes XXtX
and probably XXXsX becomes XXXtX

For a tabify operation, your above example is incorrect.
To get the same layout,
sssssssssXXXXXssssssXXXXXX becomes
ttsXXXXXttXXXXXX

Maintain a screen position separately from the character
position, and update it differently when a tab is
encountered:
screen_pos += TAB_SIZE - (screen_pos % TAB_SIZE).
Keep a running count of consecutive spaces. If a series of
spaces ends at (screen_pos % TAB_SIZE) == TAB_SIZE -1,
replace them with a tab. Else if a series of spaces ends at a tab,
delete them. For a character array, you can do this in place
by keeping a "follower" index and copying characters to
there.


.



Relevant Pages

  • Re: about formatted text
    ... I am using perl on msys in a windows operating system. ... I was manipulating a file with .TAB extension. ... I store each line in an array, after doing modifications to a couple ... The original .TAB file doesn't show that square character, ...
    (perl.beginners)
  • Re: Mix/Max/Avg Help based on dynamic ranges
    ... I did enter as array, ... The source tab (survey response) is not the prettiest of creatures. ... deemed optimal for building device profiles based on locn size and device ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Formatting index entries
    ... replace each space with a tab character ... Copy the whole cell ... use Edit>Replace to replace every tab with a space. ... you want to rip all the Index tags out of the main document. ...
    (microsoft.public.mac.office.word)
  • Re: Managing 70 checkboxes in financial graphing application
    ... to manage how the checkboxes interact with the data and the graph. ... I have a tab with the data series called "Data". ... This allows the graph to show blanks where data is missing as some series ... My idea is to read the status of all checkboxes into an array. ...
    (microsoft.public.excel.programming)
  • Re: Calculations Result Sometimes Displays 000, Sometimes 444
    ... > when I was addressing your mention of strange formatting options, ... the fill character for each tab was set to 4 on one of the ... added to a layout (not duplicate or copy / paste) will automatically ...
    (comp.databases.filemaker)