Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2002
    Location
    United Kingdom
    Posts
    1,236

    replacing x with y

    ok

    say i got a veriable called test

    how could i go through that variable and change all the 'x' characters to 'y' characters

    thanx

  2. #2
    Join Date
    Aug 2002
    Location
    Long Island
    Posts
    427
    what language? Scripting?

    PHP, PERL, C++, VB?
    John Trovato
    In Office Networks, LLC
    Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.

  3. #3
    Join Date
    Aug 2002
    Location
    Long Island
    Posts
    427
    in PHP use the following

    $test = str_replace ('x','y',$test);
    John Trovato
    In Office Networks, LLC
    Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.

  4. #4
    asp it is:
    test = Replace(test,"x","y")
    Stupid, but trying.

  5. #5
    Join Date
    Sep 2002
    Location
    Dallas, TX
    Posts
    205
    Hrm, how long can we keep this thread going?

    Perl: $test =~ s/x/y/gi;
    justin 'at' abrogo.com
    http://www.abrogo.com
    Shared Unix Hosting

  6. #6
    Join Date
    May 2002
    Location
    UK
    Posts
    2,994
    Another one

    ColdFusion: <cfset test = Replace(test,'x','y',"ALL")>

  7. #7
    Join Date
    Sep 2002
    Location
    Fremont, CA
    Posts
    30
    In C:
    while(*test) {
    if(*test == 'x') {
    *test= 'y';
    }
    test++;
    }

    or in obfuscated C:
    for(;((*test == 'x') ? *test= 'y' : 1), *test; test++);

  8. #8
    Join Date
    Aug 2002
    Location
    Long Island
    Posts
    427
    what about fortran, RPG, Colbol, Basic, Delphi, Java, Pascal, or assembly?

    that would be somthing to see some of these?
    John Trovato
    In Office Networks, LLC
    Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.

  9. #9
    Join Date
    Sep 2002
    Location
    Dallas, TX
    Posts
    205
    Java (assuming test is StringBuffer):

    Code:
    for (int x = 0; x < test.length(); x++)
    {
        if (test.charAt(x) == 'x')
                test.replace(x, 1, "y");
    }
    Last edited by cortices; 10-31-2002 at 02:44 PM.
    justin 'at' abrogo.com
    http://www.abrogo.com
    Shared Unix Hosting

  10. #10
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    3,100

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •