hi, im having a similar problem but i need one that replaces letters, and in c# format... does anyone know how to do that? ... it takes the concept of a custom encrypter, if you ve seen a game c# then what is usually

if (Control == ???)
{
 <act>
}

ive tried to make it where it does this

if (text == A || text == a)
{
newtext == r
}
jonsca commented: Don't bump old threads, start your own -1

Recommended Answers

All 5 Replies

post what the error is first of all...

but looking at that... you're comparing a string (text) to a variable (A or a)

if (text == A || text == a)
{
newtext == r
}

so instead add quotes ("") around the A and a.. which will compare the text to the strings A and a.

if (text == "A" || text == "a")
{
newtext == "r"
}

or

if you're working with chars, then add single quotes ('') around the A and a...
eg

if (text == 'A' || text == 'a')
{
newtext == 'r'
}
commented: Good answer. +6

i couldnt remember how i first set it to where that was effective, although i do understand that, its not the right direction i was going, that was my first try but after it just took every letter after it had already done that and did it again making it impossible to decode "easily".. i decided to g along with this

using System;
using System.IO;
using System.Text.RegularExpressions;

class Program
{
    static void Main()
    {

        {
            Console.Title = "Encoder";
            // This is the input string we are replacing parts from.
            string Command = Console.ReadLine();
            string[] Cmd = Command.Split(' ');
            string input = (Cmd[0]);

            // Use Regex.Replace to Replace the pattern in the input.
            // ... The pattern N.t indicates three letters, N, any character, and t.

            string A = Regex.Replace(input, "A", "-01");
            string B = Regex.Replace(A, "B", "-02");
            string C = Regex.Replace(B, "C", "-03");
            string D = Regex.Replace(C, "D", "-04");
            string E = Regex.Replace(D, "E", "-05");
            string F = Regex.Replace(E, "F", "-06");
            string G = Regex.Replace(F, "G", "-07");
            string H = Regex.Replace(G, "H", "-08");
            string I = Regex.Replace(H, "I", "-09");
            string J = Regex.Replace(I, "J", "-10");
            string K = Regex.Replace(J, "K", "-11");
            string L = Regex.Replace(K, "L", "-12");
            string M = Regex.Replace(L, "M", "-13");
            string N = Regex.Replace(M, "N", "-14");
            string O = Regex.Replace(N, "O", "-15");
            string P = Regex.Replace(O, "P", "-16");
            string Q = Regex.Replace(P, "Q", "-17");
            string R = Regex.Replace(Q, "R", "-18");
            string S = Regex.Replace(R, "S", "-19");
            string T = Regex.Replace(S, "T", "-20");
            string U = Regex.Replace(T, "U", "-21");
            string V = Regex.Replace(U, "V", "-22");
            string W = Regex.Replace(V, "W", "-23");
            string X = Regex.Replace(W, "X", "-24");
            string Y = Regex.Replace(X, "Y", "-25");
            string Z = Regex.Replace(Y, "Z", "-26");

            string a = Regex.Replace(Z, "a", "-01");
            string b = Regex.Replace(a, "b", "-02");
            string c = Regex.Replace(b, "c", "-03");
            string d = Regex.Replace(c, "d", "-04");
            string e = Regex.Replace(d, "e", "-05");
            string f = Regex.Replace(e, "f", "-06");
            string g = Regex.Replace(f, "g", "-07");
            string h = Regex.Replace(g, "h", "-08");
            string i = Regex.Replace(h, "i", "-09");
            string j = Regex.Replace(i, "j", "-10");
            string k = Regex.Replace(j, "k", "-11");
            string l = Regex.Replace(k, "l", "-12");
            string m = Regex.Replace(l, "m", "-13");
            string n = Regex.Replace(m, "n", "-14");
            string o = Regex.Replace(n, "o", "-15");
            string p = Regex.Replace(o, "p", "-16");
            string q = Regex.Replace(p, "q", "-17");
            string r = Regex.Replace(q, "r", "-18");
            string s = Regex.Replace(r, "s", "-19");
            string t = Regex.Replace(s, "t", "-20");
            string u = Regex.Replace(t, "u", "-21");
            string v = Regex.Replace(u, "v", "-22");
            string w = Regex.Replace(v, "w", "-23");
            string x = Regex.Replace(w, "x", "-24");
            string y = Regex.Replace(x, "y", "-25");
            string z = Regex.Replace(y, "z", "-26");

            string AA = Regex.Replace(z, "-01", "(BA)");
            string BB = Regex.Replace(AA, "-02", "(CB)");
            string CC = Regex.Replace(BB, "-03", "(DC)");
            string DD = Regex.Replace(CC, "-04", "(ED)");
            string EE = Regex.Replace(DD, "-05", "(FE)");
            string FF = Regex.Replace(EE, "-06", "(GF)");
            string GG = Regex.Replace(FF, "-07", "(HG)");
            string HH = Regex.Replace(GG, "-08", "(IH)");
            string II = Regex.Replace(HH, "-09", "(JI)");
            string JJ = Regex.Replace(II, "-10", "(KJ)");
            string KK = Regex.Replace(JJ, "-11", "(LK)");
            string LL = Regex.Replace(KK, "-12", "(ML)");
            string MM = Regex.Replace(LL, "-13", "(NM)");
            string NN = Regex.Replace(MM, "-14", "(ON)");
            string OO = Regex.Replace(NN, "-15", "(PO)");
            string PP = Regex.Replace(OO, "-16", "(QP)");
            string QQ = Regex.Replace(PP, "-17", "(RQ)");
            string RR = Regex.Replace(QQ, "-18", "(SR)");
            string SS = Regex.Replace(RR, "-19", "(TS)");
            string TT = Regex.Replace(SS, "-20", "(UT)");
            string UU = Regex.Replace(TT, "-21", "(VU)");
            string VV = Regex.Replace(UU, "-22", "(WV)");
            string WW = Regex.Replace(VV, "-23", "(XW)");
            string XX = Regex.Replace(WW, "-24", "(YX)");
            string YY = Regex.Replace(XX, "-25", "(ZY)");
            string ZZ = Regex.Replace(YY, "-26", "(AZ)");

            string AAA = Regex.Replace(ZZ, "A", "-01");
            string BBB = Regex.Replace(AAA, "B", "-02");
            string CCC = Regex.Replace(BBB, "C", "-03");
            string DDD = Regex.Replace(CCC, "D", "-04");
            string EEE = Regex.Replace(DDD, "E", "-05");
            string FFF = Regex.Replace(EEE, "F", "-06");
            string GGG = Regex.Replace(FFF, "G", "-07");
            string HHH = Regex.Replace(GGG, "H", "-08");
            string III = Regex.Replace(HHH, "I", "-09");
            string JJJ = Regex.Replace(III, "J", "-10");
            string KKK = Regex.Replace(JJJ, "K", "-11");
            string LLL = Regex.Replace(KKK, "L", "-12");
            string MMM = Regex.Replace(LLL, "M", "-13");
            string NNN = Regex.Replace(MMM, "N", "-14");
            string OOO = Regex.Replace(NNN, "O", "-15");
            string PPP = Regex.Replace(OOO, "P", "-16");
            string QQQ = Regex.Replace(PPP, "Q", "-17");
            string RRR = Regex.Replace(QQQ, "R", "-18");
            string SSS = Regex.Replace(RRR, "S", "-19");
            string TTT = Regex.Replace(SSS, "T", "-20");
            string UUU = Regex.Replace(TTT, "U", "-21");
            string VVV = Regex.Replace(UUU, "V", "-22");
            string WWW = Regex.Replace(VVV, "W", "-23");
            string XXX = Regex.Replace(WWW, "X", "-24");
            string YYY = Regex.Replace(XXX, "Y", "-25");
            string output = Regex.Replace(YYY, "Z", "-26");

            //identify file
            DateTime CurrTime = DateTime.Now;
            string encoded = ("C:/Users/User/Desktop/ENC-M" + CurrTime.Month + "-D" + CurrTime.Day + "-H" + CurrTime.Hour + "-M" + CurrTime.Minute + "-S" + CurrTime.Second + ".txt");

            //create text file
            FileStream fs = null;
            if (!File.Exists(encoded))
            {
                using (fs = File.Create(encoded))
                {

                }
            }

            // create a writer and open the file
            TextWriter tw = new StreamWriter(encoded);

            // write a line of text to the file
            tw.WriteLine(output);

            // close the stream
            tw.Close();

            // Write the output.
            Console.WriteLine(output);
            //Pause
            Console.Read();
        }
    }
}

that is my entire code so if anyone wants to perfect it be my guest... but i still have one glitch...what this program is designated to do is create a text file that gets writen by text that you input into the console, but it only works once then shuts down... i dont remember how to make it start over but thats the lease of it, the other glitch is that when creating the file it wont work unless i specify MY exact location which is dffrent then people whom i work with who need to create new coded texts. please help me fix these error =(

instead of specifying a hard coded path to the desktop use this

My.Computer.FileSystem.SpecialDirectories.Desktop

this is VB... but im sure C# has something similar or exactly the same, havent needed to do something like that in c# yet... just vb...

so try and port that to C# and it would work like a dream...

and if you want it to continue running until you are done...

use a loop

char done = 'N'
do
{

//code
//ask user if they are done
done = ans //(which is either y or n, is up to you)
}
while(done.toUpper() == 'Y')

there are several ways to loop it :)

hope this helps

that way i can understand but its not reading most of the varibles in the code... for example My. is not found (does not exist in current text) , ans and toupper are not reading either.... ive never used char before or buffer, it just seems pointless to me.

here is the C# code for desktop

Environment.SpecialFolder.Desktop

and for the char to get it to upper...

do this

done.ToString().ToUpper()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.