A
A
Acroni2015-09-12 22:50:16
Programming
Acroni, 2015-09-12 22:50:16

How to process a text document with little blood?

There is a text file, each line is one word. It is necessary to calculate, say, the alphabetical sum of letters for each word (a=1, b=2, etc.) and put it in the same line.
In view of the primitiveness of the task, my search lies more in the plane of searching for a text editor that can do this, and not for a software algorithm.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
G
Green Elephant, 2015-09-12
@GreenElephantt

It will be much more convenient to use RegExp-regular expressions, through them you can safely replace everything, it will not be difficult to calculate everything later, I think there are functions like eval () in javascript almost everywhere
for even less blood here is a service for reg expressions refiddle

D
DrunkMaster, 2015-09-12
@DrunkMaster

A text editor will not do this.
First, the weights a=1, b=2, etc. are assigned. Then you can immediately replace all the letters in the entire document with numbers. Then either go through each line and count the sum of the digits in it, or split the document into arrays = lines and count array_sum for each line (in php for example). Everything.

X
xmoonlight, 2015-09-13
@xmoonlight

If you're doing a hash for each string, it's better to use hash() in PHP.
If exactly a=1, b=2, etc., then simply:

$alpabet='абвгд..............я';
$str = 'string';
$chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);
$summ=0;
foreach ($chars as $c)
  $summ+=array_keys($alpabet,$c)+1;

A
Alejandro Esquire, 2015-09-12
@A1ejandro

the simplest task, for example, in school Pascal ... reading a line, forming a new line, writing to a file. in general, about 6 lines of code....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question