Re: How to dedect 4 consecutive space
- From: "Larry Barowski" <MElarrybar-AT-eng_DOT_auburnANOTHERDOTeduEND>
- Date: Sat, 31 Dec 2005 07:07:47 -0600
<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.
.
- Prev by Date: Re: JList getSelectedValue returning null
- Next by Date: Re: generic oversight?
- Previous by thread: Re: How to dedect 4 consecutive space
- Index(es):
Relevant Pages
|