спецы по с/с++ помогите чайнику.. -)

111001
Posts: 11
Joined: 04 Apr 2004 01:40

Re: спецы по с/с++ помогите чайнику.. -)

Post by 111001 »

theukrainian wrote:
111001 wrote:
theukrainian wrote:По-моему не работает когда число приходится на границу строки в которой вы делаете replace.

Would you provide an example, please?

i could be wrong... but i think situation like the following:
"abcd.......123456abcd", where, say, '3' is symbol number MAXLINELENGTH (ie, if MAXLINELENGTH is 1000, then '3' is symbol number 1000, since fgets() will read at most MAXLINELENGTH - 1 (and null-terminate)...or stop at '\n' if it sees one).

There reason it seems to me that it does not work is because replace function is going to be called on "abcd....12", resulting in output of "abce...(12", and then it'll be called again on "3456.... " resulting in output of "(3456).....".

To fix this, replace() would need to keep state between invocations, but this would not be pretty.

I could be off by one, but what matters is the idea itself :)

.. am I missing something?


Спасибо за ответ.
Я, конечно, предполагал, что MAXLINELENGTH выбрана
достаточно большой, так что любая строка заведомо короче. Иначе все это лучше делать на бинарном потоке,
не разбивая на строки.
ig
Уже с Приветом
Posts: 491
Joined: 09 Apr 2000 09:01
Location: Tigard, OR

Post by ig »

Sw_Lem,

тут уже рекомендовали perl, вот с таким шаблоном должно работать:

<pre>s/([^(\d]|^)(\d+)(?![)\d])/$1($2)/g</pre>

Return to “Вопросы и новости IT”