Código: Seleccionar todo

Public Function aLTrim(A As String)
On Error Resume Next
'============================================================'
' AX: aLTrim '
' Uso: Call aLTrim(" Texto") '
'============================================================'
Dim b As Long
Dim c As Long
If Len(A) = 0 Then Exit Function
For b = 1 To Len(A) Step 1
If Mid(A, b, 1) <> Chr(32) Then c = b: Exit For
Next b
aLTrim = Mid(A, c, Len(A) - (c - 1))
End Function
La función aLTrim elimina los espaciones en blanco en la parte izquierda de la String, Cadena, o Texto.
Si el Texto fuera: " Hola mundo" entonces el resultado sería "Hola mundo"

Código: Seleccionar todo

Public Function aRTrim(A As String)
On Error Resume Next
'============================================================'
' AX: aRTrim '
' Uso: Call aRTrim("Texto ") '
'============================================================'
Dim i As Long
Dim k As Long
If Len(A) = 0 Then Exit Function
For i = Len(A) To 1 Step -1
If Mid(A, i, 1) <> Chr(32) Then k = i: Exit For
Next i
aRTrim = Mid(A, 1, Len(A) - (Len(A) - k))
End Function
La función aRTrim elimina los espacios vacíos de una cadena que se encuentren a la derecha...Si el texto fuese "Hola mundo " entonces sería "Hola mundo".

Código: Seleccionar todo

Public Function aTrim(A As String)
On Error Resume Next
'============================================================'
' AX: aTrim '
' Uso: Call aTrim(" Texto ") '
'============================================================'
Dim f As Long
Dim g As Long
Dim h As Long
Dim i As String
If Len(A) = 0 Then Exit Function
For f = 1 To Len(A) Step 1
If Mid(A, f, 1) <> Chr(32) Then g = f: Exit For
Next f
i = Mid(A, g, Len(A) - (g - 1))
For f = Len(i) To 1 Step -1
If Mid(i, f, 1) <> Chr(32) Then h = f: Exit For
Next f
aTrim = Mid(i, 1, Len(i) - (Len(i) - h))
End Function
Y por último la función aTrim hace lo mismo que las otras dos anteriores funciones simultaneamente.
Te han quedado muy bien AX, y para no dejar mi mensaje solamente en el agradecimiento, te dejo unas funciones que hice yo para retroalimentar el post que hacen lo mismo pero en delphi, solo me falto hacer la combinacion de ambas pero ya teniendo la izquierda y derecha la ultima es muy facil de hacer :P

Insisto te han quedado muy bien, sigue así AX llegarás lejos!!

PD: Esto debe ir en fuentes y textos de programación!! :P

Código: Seleccionar todo

Function RLTrim(szEntrada:String):String;
{->Coder - Linkgl <-}
{->Funcion-linkgl.blogspot.com}
{->indetectables.net<-}
var
i:Integer;
begin
for i:=length(szEntrada) downto 1 do
begin
  if not(copy(szEntrada,i,1)=' ') then
  begin
    Result:=copy(szEntrada,1,i);
    exit
  end
end
end;
Function LLTrim(szEntrada:String):String;
{->Coder - Linkgl <-}
{->Funcion-linkgl.blogspot.com}
{->indetectables.net<-}
var
i:Integer;
begin
for i:=1 to length(szEntrada) do
begin
  if not(copy(szEntrada,i,1)=' ') then
  begin
    Result:=copy(szEntrada,i,length(szEntrada));
    exit
  end
end
end;
{->EJEMPLO DE USO<-}
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text:=RLTrim('hola soy linkgl         ');
Edit2.Text:=LLTrim('      hola soy linkgl');
end;
end.
//mHmm..
Responder

Volver a “Fuentes”