We help IT Professionals succeed at work.

Remove a word from a memo.

CodedK
CodedK asked
on
528 Views
Last Modified: 2010-04-05
Hi.

I'm loading a text file in a memo.

I'd like to cound the letters in each line and if it exceeds a certain number then
i'd like to delete what ever comes after.

For example:

Line 1: "This is a phrase in line one"
If the cutoff number is 11 then line 1 should be
Line 1: "This is a p..."

I can think of one to ways of doing that.. with copy maybe but i'd like something fast.

Thanks in advance.
Comment
Watch Question

Cesario LababidiSoftware developer
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Top Expert 2007

Commented:
check the following code:

function loadFile(name:string; list:TStrings; cut:word):boolean;
var f:textfile; s:string;
begin
  result:=false;
  list.clear;
  assignfile(f,name);
  try
    reset(f);
    try
      while not eof(f) do
      begin
        readln(f,s);
//        if length(s)>cut then begin
          delete(s,cut,length(s));// delete procedure checks to see if index (cut) is within 1 and length(s) and if it's not, it doesn't do anything (you can check the source code of system.pas if you don't believe me :)  so there is no need fot an if here (=> small speed optimization))
//          s:=s+'...';// in your example you done this, so I guess you want it :) If you do want it, then uncomment the 3 commented lines
//        end;
        list.add(s);
      end;
      result:=true;
    finally
      closefile(f);
    end;
  except
  end;
end;

Commented:
ciuly,
I am not sure...
Is Delete quicker than SetLength?
Top Expert 2007
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
Thanks for that ciuly.
It is interesting to know.
I feel like I should be giving you points for that :)
CodedKSenior Software Engineer
CERTIFIED EXPERT

Author

Commented:
kfoster11 this isnt the problem but thanks for the code :)
Anyway I'll increase the points to split because ...ciuly that was impressive :)
CERTIFIED EXPERT

Commented:
Im interested in knowing what you were trying to accomplish.
CodedKSenior Software Engineer
CERTIFIED EXPERT

Author

Commented:
Just to cut a phrase that exeeds a specific length kfoster11.
Top Expert 2007

Commented:
> Anyway I'll increase the points to split because ...ciuly that was impressive :)
thanks.. I guess :) It's just one way of measuring the execution time of "something" You'll get to use something like that when you will be in need for speed optimization, so it's good to know :)

cheers
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.