Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Necesito función para modificar carácteres. (https://www.clubdelphi.com/foros/showthread.php?t=49687)

samsagaz 26-10-2007 23:14:16

Necesito función para modificar carácteres.
 
Buenos, días, estoy necesitando una función o proceso para poder modificar un string.

Por ejemplo lo que estoy buscando sería.

Tengo el String "Auto" y tengo q volver a escribir el string utilizando todos los errores de tipeo, por ejemplo

quto
wuto
suto
xuto
zuto

ayto
ahto
ajto
akto
aito
a7to
a8to

o sea, las letras siguientes a la letra en cuestion (valga la redundancia) :D

Espero que alguien pueda ayudarme.

Gracias.

BlueSteel 27-10-2007 00:23:26

Hola...

en realidad no se si esto te pueda servir.. la utilizo en Delphi 7

Código Delphi [-]
AnsiReplaceStr('Auxo''],'x','t')

lo que hace es reemplazar la x por la t dentro del string auxo

más bien.. creo que te puede servir una función como diccionario inteligente...tipo word...

si encuentras algo.. ponlo aca para echarle un vistazo:p suerte

samsagaz 27-10-2007 01:54:35

Un amigo me ha ayudado, les mustro el codigo, puede q alguien lo necesite :)

Código Delphi [-]
 
 
type
  TKeySet = Array[1..4] of Array[1..10] of Char;
  TForm1 = class(TForm)
    Edit1: TEdit;
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
  protected
    procedure FindWords(const Keys: TKeySet; AWord: String; Pos: Integer);
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FindWords(const Keys: TKeySet; AWord: string; Pos: Integer);
var
  i,j: Integer;
  x,y: Integer;
  NewWord: String;
begin
  { Por cada KeySet }
  for i := 1 to 4 do begin
    { Por cada caracter en KeySet }
    for j := 1 to Length(Keys[i]) do begin
      { Si el caracter iguala al de AWord[Pos] }
      if AWord[Pos] = Keys[i][j] then begin
        { Mirar un Keyset hacia arriba y uno hacia abajo }
        for x := i-1 to i+1 do begin
          { Y también un caracter a la izquierda y a la derecha }
          for y := j-1 to j+1 do begin
            { Si la posición es incorrecta, o igual a la del caracter actual o es un #0 en keyset -> saltaeralo }
            if (x < 1) or (x > 4) or (y < 1) or (y > 10) or (Keys[x][y] = #0) or ((x = i) and (y = j)) then
              Continue;
            { Sino, escribir la palabra alternativa }
            NewWord := AWord;
            NewWord[Pos] := Keys[x][y];
            Memo1.Lines.Add(NewWord);
          end;
        end;
        Exit;        
      end;
    end;
  end;
end;
procedure TForm1.Button1Click(Sender: TObject);
const
  { Caracteres #0 son saltados }
  Keys: TKeySet = (('1','2','3','4','5','6','7','8','9','0'),
                   ('q','w','e','r','t','y','u','i','o','p'),
                   ('a','s','d','f','g','h','j','k','l', #0),
                   ('z','x','c','v','b','n','m', #0, #0, #0));
var
  i,j: Integer;
  AChar: Char;
  AWordPtr: PChar;
  Ptr: PChar;
begin
  AWordPtr := PChar(LowerCase(Edit1.Text));
  try
    { Recorrer string por palabras }
    while AWordPtr <> nil do begin
      Ptr := StrScan(AWordPtr, ' ');
      if Ptr <> nil then
        Ptr^ := #0;
      { Recorrer cada letra de cada palabra }
      Memo1.Lines.Add('----- Alternativas de ' + AWordPtr + ' -----');
      for i := 1 to Length(AWordPtr) do begin
        if AWordPtr[i] = ' ' then
          Continue;
        { Buscar alternativas }
        FindWords(Keys,AWordPtr,i);
        Memo1.Lines.Add('');
      end;
      { Apuntar a la siguiente palabra en el string }
      if Ptr <> nil then begin
        Ptr^ := ' ';
        Inc (Ptr);
      end;
      AWordPtr := Ptr;
    end;
    { Hacer Scroll en el memo a la primera línea }
    Memo1.SelStart := 0;
    Memo1.SelLength := 1;
  finally
    Memo1.Lines.EndUpdate;
  end;
end;
end.

Gracias a Anibal por el código.

cHackAll 27-10-2007 02:03:20

Usa las etiquetas amigo samsagaz, [ delphi ] código y [ /delphi ] (sin espacios)... o lo marcas y le haces

samsagaz 27-10-2007 02:06:49

Cita:

Empezado por cHackAll (Mensaje 241614)
Usa las etiquetas amigo samsagaz, [ delphi ] código y [ /delphi ] (sin espacios)... o lo marcas y le haces


gracias, ya lo he solucionado :)

Delfino 27-10-2007 11:04:37

Eso se llama reinventar la rueda, con la cantidad de funciones existentes y optimizadas q tiene Delphi en la unidad StrUtils, me vienen a la cabeza por lo menos StringReplace o StuffString ;)


La franja horaria es GMT +2. Ahora son las 05:07:27.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi