Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Общие вопросы > Покетное удаление (и преобразование) текста.


Автор: feosr 20.1.2007, 21:50
Вобщем я 2 дня мучаюсь, но у меня не получается)

Нужна прога для удаления из файлов якорей.

Примеры якорей:

Код
<a name="d0e275366"></a> - первый
<a name="d0e275368"></a> - второй

 
А также для преобразования ссылок.

Пример:

Код
<a href="_3d_maps" title="3D Maps">3D Maps</a>
 надо преобразовать в 
Код
[[_3d_maps|3D Maps]]
.

прога должна обрабатывать все файлы в папке. Желательно коментариями в коде)))

может ли ктонибудь дать мне хотябы пример такой программы а лучше исходник готовой. но если можно прокоментируйте код в этом случае. но это лишнее, я сам какнить попробую разобраться.?

Автор: VladBD 20.1.2007, 23:01
а указанные фрагменты это отдельные строки или встречаются в строках?

Автор: feosr 20.1.2007, 23:12
это части строк. тоесть  я незнаю в какой строке будет следующий якорь / ссылка. Якорей на странице как минимум 2-3. Страниц - 2921.

Автор: VladBD 20.1.2007, 23:32
т.е. может быть так?
бла-бла<a name="d0e275366"></a>бла-бла<a name="d045645645275366"></a>бла-бла

вообще наверное рыть надо в сторону регулярных выражений
http://forum.vingrad.ru/topic-133016.html

берешь в цикле файлы, открываешь каждый и перечитываешь в другой файл, при этом парсишь строки рег. выражениями

Автор: W4FhLF 21.1.2007, 07:42
Приведи примеры как можно большего кол-ва вариантов и текстов, выдели какие части на какие нужно заменить, помогу решить задачу с помощью регулярных выражений.

Автор: feosr 21.1.2007, 11:08
сейчас:

Код
<div class="sect1">
         ==<a name="_2_rail_sweep_surface"></a>2-Rail Sweep Surface <span class="inlinemediaobject"> http://3dmaxhelp.com/graphics/but_2railsweepsurf.gif"></span>==
         </div>
         <p class="PathAnnotation"><a name="d0e100720"></a><a name="d0e100721"></a>Select NURBS object. &gt; Modify panel &gt; Create Surfaces rollout &gt; Dependent Surfaces group box &gt; 2-Rail<a name="d0e100723"></a><br><br>Select NURBS object. &gt; Modify panel &gt; NURBS toolbox &gt; Create 2-Rail Sweep button
         </p>
         <p class="Body"><a name="d0e100733"></a>Sweep surfaces are constructed from curves. A 2-rail sweep surface uses at least three curves. Two curves, the "rails," define
            the two edges of the surface. The other curves define the surface's cross sections. A 2-rail sweep surface is similar to a
            1-rail sweep. The additional rail gives you more control over the shape of the surface.
         </p>
         <div class="mediaobject"> http://3dmaxhelp.com/graphics/il_nurbs_sweep2.jpg"><div class="caption"><a name="d0e100738"></a><p class="BodyCaption">Sweep surface created with two rails</p>
            </div>
         </div>
         <p class="Body"><a name="d0e100741"></a>The cross-section curves should intersect the rail curves. If the cross sections don't intersect the rails, the resulting
            surface is unpredictable. In addition, the initial points of the rails and the endpoints of the first cross-section curve
            must be coincident. Use NURBS Snaps to accomplish this.
         </p>


то часть стрнички.

в них надо удалить:

Код

<a name="d0e100720"></a>
<a name="d0e100721"></a>
<a name="d0e100741"></a>
<a name="d0e100733"></a>
<a name="d0e100723"></a>

И т.д.

ну и ссылки переделать)

для тех кто просто непонимает нах оно мне:

мне надо конвертировать разметки из HTML в WIKI для проекта 3dMaxHelp.com.

Автор: W4FhLF 21.1.2007, 13:42
Код

function FixText(sData: string): string;
var
  exp: TRegExpr;
begin
  exp := TRegExpr.Create;
  exp.Expression := '\<a name\=\"[a-z0-9]{9}\"\>\<\/a\>';
  Result := exp.Replace(sData, '');
  exp.Free;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Memo1.Text := FixText(Memo1.Text);
end;


Функция FixText удаляет якори. После обработки в Memo1 такой текст:

Код

<div class="sect1">
         ==<a name="_2_rail_sweep_surface"></a>2-Rail Sweep Surface <span class="inlinemediaobject"> 
http://3dmaxhelp.com/graphics/but_2railsweepsurf.gif"></span>==
         </div>
         <p class="PathAnnotation">Select NURBS object. &gt; Modify panel &gt; Create Surfaces rollout &gt; 
Dependent Surfaces group box &gt; 2-Rail<br><br>Select NURBS object. &gt; Modify panel &gt; NURBS toolbox &gt; Create 2-Rail Sweep 
button
         </p>
         <p class="Body">Sweep surfaces are constructed from curves. A 2-rail sweep surface uses at least three curves. Two curves, the "rails," 
define
            the two edges of the surface. The other curves define the surface's cross sections. A 2-rail sweep surface is similar to a
            1-rail sweep. The additional rail gives you more control over the shape of the surface.
         </p>
         <div class="mediaobject"> http://3dmaxhelp.com/graphics/il_nurbs_sweep2.jpg"><div class="caption"><p 
class="BodyCaption">Sweep surface created with two rails</p>
            </div>
         </div>
         <p class="Body">The cross-section curves should intersect the rail curves. If the cross sections don't intersect the rails, the resulting
            surface is unpredictable. In addition, the initial points of the rails and the endpoints of the first cross-section curve
            must be coincident. Use NURBS Snaps to accomplish this.
         </p>


Чтобы переформировать ссылки мне нужен текст с нескольмим примерами этих ссылок, ты таковой не предоставил.

Автор: feosr 21.1.2007, 13:48
отрывок со ссылками:

Код

<h2 class="title" style="clear: both">Using the Transform Type-In
                  </h2>
               </div>
            </div>
            <p class="Body"><a name="d0e37962"></a>The <a href="transform_type_in" title="Transform Type-In">Transform Type-In</a> is a small dialog you can keep on your screen while you work. Its contents update to match the currently active transform
               and selected object.
            </p>
            <p class="Body"><a name="d0e37967"></a> There is also a coordinate display area on the status bar where you can monitor and update objects’ position, rotation, and
               scale values.
            </p>
            <div class="sect3">
               <div class="titlepage">
                  <div>
                     <h3 class="title"><a name="d0e37969"></a>Using Type-In with Sub-Object Selection
                     </h3>
                  </div>
               </div>
               <p class="Body"><a name="d0e37972"></a>You can use Transform Type-In with any sub-object selection or gizmo. The transform affects the axis tripod for the selection.
               </p>
               <p class="Body"><a name="d0e37974"></a>Absolute and offset world coordinates are those of the object's or selection's coordinate system, whose origin is indicated
                  by the axis tripod. If multiple vertices are selected, the tripod is at the center of the selection and its location is given
                  in world coordinates. 
               </p>
               <p class="Body"><a name="d0e37976"></a>Because axis tripods cannot be scaled, Absolute Scale fields are unavailable when you are at a sub-object level.
               </p>
               <p class="Body"><a name="d0e37978"></a>See <a href="basics_of_creating_and_modifying_objects" title="Basics of Creating and Modifying Objects">Basics of Creating and Modifying Objects</a> for information on sub-object selection and gizmos. 
               </p>


сча буду прилажываить твой код)

Автор: W4FhLF 21.1.2007, 14:06
Знач так, загнал в Memo1 этот текст, пропарсил такой функцией:

Код

function FixText(sData: string): string;
var
  exp: TRegExpr;
begin
  exp := TRegExpr.Create;
  exp.Expression := '\<a name\=\"[a-z0-9]{4,10}\"\>\<\/a\>';
  Result := exp.Replace(sData, '');
  exp.Expression := '\<a href\=\"';
  Result := exp.Replace(Result, '[[');
  exp.Expression := '\" title\=\"';
  Result := exp.Replace(Result, '|');
  exp.Expression := '\"\>[-_ a-zA-Z0-9\s]+\<\/a\>';
  Result := exp.Replace(Result, ']]');
  exp.Free;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Memo1.Text := FixText(Memo1.Text);
end;


В результате имеем такой текст на выходе:

Код

<h2 class="title" style="clear: both">Using the Transform Type-In
                  </h2>
               </div>
            </div>
            <p class="Body">The [[transform_type_in|Transform Type-In]] is a small dialog you can keep on your 
screen while you work. Its contents update to match the currently active transform
               and selected object.
            </p>
            <p class="Body"> There is also a coordinate display area on the status bar where you can monitor and update objects’ position, rotation, and
               scale values.
            </p>
            <div class="sect3">
               <div class="titlepage">
                  <div>
                     <h3 class="title">Using Type-In with Sub-Object Selection
                     </h3>
                  </div>
               </div>
               <p class="Body">You can use Transform Type-In with any sub-object selection or gizmo. The transform affects the axis tripod for the 
selection.
               </p>
               <p class="Body">Absolute and offset world coordinates are those of the object's or selection's coordinate system, whose origin is indicated
                  by the axis tripod. If multiple vertices are selected, the tripod is at the center of the selection and its location is given
                  in world coordinates. 
               </p>
               <p class="Body">Because axis tripods cannot be scaled, Absolute Scale fields are unavailable when you are at a sub-object level.
               </p>
               <p class="Body">See [[basics_of_creating_and_modifying_objects|Basics of Creating and Modifying Objects]] for information on sub-object selection and gizmos. 
               </p>


Все условия, которые ты дал учёл, но в твоих примерах могут быть и исключения, поэтому я сразу попросил как можно больше вариантов привестиsmile

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)