?
Solved

strange problem with space (' ')

Posted on 2003-03-20
17
Medium Priority
?
127 Views
Last Modified: 2010-04-04
I have to cut of the spaces before en behind a text
I do it with Trim(text)
But now, I have a text (from html-source) with emty places, but it aren't spaces. (Trim doesn't work)
I capy-paste 3 caracters of them here between ''  --->  '   '

How can I delete those caracters at the end of a string?
0
Comment
Question by:Steve2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 2
  • +3
17 Comments
 

Expert Comment

by:da-vinci
ID: 8175237
Use the madStrings, (free available) at http://help.madshi.net/StringDel.htm


The Trim functions delete all control and space characters at the end and the beginning of the string.

procedure   TrimStr (  var str: string);
function RetTrimStr (const str: string) : string;
0
 

Expert Comment

by:Imagine
ID: 8176194
Hi,

First of all; those characters are defenitly spaces.

Something more code but maybe usefull (at least,I hope so):

this code deletes the last three spaces from a string

[code]

var
  s : string = 'Lot of spaces I wish to delete   ';

implementation

procedure TForm1.Button1Click(Sender: TObject);
var
  i, i1 : integer;
begin
  for i := 1 to Length(s) do begin
    i1 := lenght(s);
    i1 := i1 - 3;
    if (Ord(s[i]) = 32) and (i >= i1)  then begin
      delete(s,i,1);
       button1.click;
      exit;
    end;
  end;
  form1.Label1.Caption := s;
end;
0
 

Expert Comment

by:Klooge
ID: 8177268
The SysUtils Function Trim
"trims leading and trailing spaces and control characters from a string" as it says in the Help.

Make sure you are using it as a Function :
sTrimmed := Trim(sUntrimmedString);

and not as a Procedure :
Trim(sUntrimmedString);

The last statement, of course, does nothing.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:ILE
ID: 8177289
send mi html  file
with that caracters

stuf what u copy and paste are spaces
:))

ile@unet.com.mk
0
 

Author Comment

by:Steve2000
ID: 8177623
I use it like a function:
sTrimmed := Trim(sUntrimmedString);

I find this character in this site (html-code):
http://www.radiocontact.be/nl/super50/super50.asp

example in the line:
<td x:str="SARAH   "><font face="Verdana" size="2" color="#155499">SARAH   </font></td>
0
 
LVL 22

Expert Comment

by:grg99
ID: 8177684
Aha, I see, it's a space with the high bit set.

I would write a trim function that would throw away anything less than space, or greater than ~:

function ReallyTrim( S: String  ): String;
var Out: String;
   i: integer;
begin
    Out := '';
    for i := 1 to Length( S ) do
      begin
           Ch := S[ i ];
           if Ch >= ' ' then
             if Ch <= '~' then
                Out := Out + Ch;
       end;
    ReallyTrim := Out;
end;

0
 

Author Comment

by:Steve2000
ID: 8177705
Wich caracters will be deleted then?
' ', '~', ...
0
 

Author Comment

by:Steve2000
ID: 8177744
btw, the code doesn't work :s
0
 
LVL 3

Expert Comment

by:ILE
ID: 8177762
the solution


function realtrim(s:string):string;
var s1:string;
     i:integer;
begin
s1:='';
for i:=1 to length(s) do if (ord(s[i])>32) and (ord(s[i])<255) then s1:=s1+s[i];
realtrim:=s1;
end;



this will work
:))
0
 
LVL 3

Expert Comment

by:ILE
ID: 8177774
OOOOOOOOOOOOOOOOOOPPPPPPPPPPPPPSSSS

this will work on any cases
but instead of <255 must be <127    

just a litle ERROR



correct problem

:)))
0
 

Author Comment

by:Steve2000
ID: 8177780
why 127 and not 255?

But I only need to delete de ' ' at the end and the beginning of a text, not in the middle
0
 
LVL 22

Expert Comment

by:grg99
ID: 8177793
My code should work-- I did forget to declare Ch: char;
Also faster to declare ( const S: String );
0
 
LVL 3

Expert Comment

by:ILE
ID: 8177830
this will be delete all not-ascii  caracters

and all types of spaces
if u wona del just spaces code will be


function realtrim(s:string):string;
var s1:string;
    i:integer;
begin
s1:='';
for i:=1 to length(s) do if not((s[i]=#32) or (s[i]=#160) or (s[i]=#255)) then s1:=s1+s[i];
realtrim:=s1;
end;

this will be delete all caind of spaces and just spaces

:))





0
 

Author Comment

by:Steve2000
ID: 8177898
why 127 and not 255?

But I only need to delete de ' ' at the end and the beginning of a text, not in the middle
0
 
LVL 3

Accepted Solution

by:
ILE earned 90 total points
ID: 8178070
NOWWWWW I ANDERSTAND



function tform1.suptrim(s:string):string;
var I:integer;
    s1,s2:string;
begin
s1:=s;
for i:=1 to length(s) do
if (s[i]=#32) or (s[i]=#160) or (s[i]=#255) then
   s1:=copy(s,i+1,length(s)) else break;
   s2:=s1;
for i:=length(s1) downto 1 do
if (s2[i]=#32) or (s2[i]=#160) or (s2[i]=#255) then
   s1:=copy(s2,1,i-1) else break;
suptrim:=s1;

end;



this is working 100%
0
 

Author Comment

by:Steve2000
ID: 8178080
My Strange ' ' is the caracter Chr(160) (ASCII)
0
 
LVL 3

Expert Comment

by:ILE
ID: 8178146
yep :))
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question