|
Hi dear,
How can I convert the following VB Script to C# ?
Function En2Fr (sStr)<br />
<br />
Dim nLen, i, ch, sFrStr<br />
<br />
nLen = Len(sStr)<br />
<br />
if nLen = 0 OR IsNull(nLen) then<br />
En2Fr = sStr<br />
Exit Function <br />
end if<br />
<br />
sFrStr = ""<br />
<br />
for i = 1 to nLen<br />
ch = Mid(sStr, i, 1)<br />
if 48 <= Asc(ch) AND Asc(ch) <= 57 then<br />
ch = ChrW(Asc(ch) + 1728)<br />
end if<br />
sFrStr = sFrStr + ch<br />
next<br />
<br />
En2Fr = sFrStr<br />
<br />
End Function<br />
Thank you in advance.
|
|
|
|
|
Have you tried doing the conversion yourself, or are you just too lazy? If you have tried it, which part are you specifically having problems with?
Regards,
Alvaro
Hey! It compiles! Ship it.
|
|
|
|
|
I have a problem to get the ascii characters in fact i have a problem with converting these lines
<br />
if 48 <= Asc(ch) AND Asc(ch) <= 57 then<br />
ch = ChrW(Asc(ch) + 1728)<br />
|
|
|
|
|
You can convert "Asc(ch)" to "(int)ch" or
System.Text.ASCIIEncoding.ASCII.GetBytes(new char[1]{'c'});
if ( (48 <= ((int)ch)) && (((int)ch) <= 57) ){
ch = (char) (((int)ch) + 1728);
}
|
|
|
|
|
|
The AscW and ChrW functions are directly equivalent to casting between a char and an int ;
To correctly duplicate the Chr and Asc functions needs a bit more work. You could add a reference to the Microsoft.VisualBasic assembly, and use the static methods of the Strings class. Alternatively, you can use:
public static char Chr(int i)
{
if (0 <= i && i <= 127) return (char)i;
if (i < -0x8000 || i > 0xFFFF) throw new ArgumentOutOfRangeException();
System.Text.Encoding enc = System.Text.Encoding.Default;
if (enc.GetMaxByteCount(1) == 1 && (i < 0 || i > 0xFF))
throw new ArgumentOutOfRangeException();
System.Text.Decoder dec = enc.GetDecoder();
byte[] b;
char[] c;
if (0 <= i && i <= 0xFF)
{
b = new byte[1];
b[0] = checked((byte) (i & 0xFF));
c = new char[1];
dec.GetChars(b, 0, 1, c, 0);
}
else
{
b = new byte[2];
b[0] = checked((byte) ((i >> 8) & 0xFF));
b[1] = checked((byte) (i & 0xFF));
c = new char[1];
dec.GetChars(b, 0, 2, c, 0);
}
return c[0];
}
public static int Asc(char ch)
{
int i = (int)ch;
if (i < 128) return i;
System.Text.Encoding enc = System.Text.Encoding.Default;
char[] c = new char[] {ch};
byte[] b = enc.GetBytes(c);
if (b.Length == 2 && BitConverter.IsLittleEndian)
{
byte t = b[0];
b[0] = b[1];
b[1] = t;
}
if (b.Length == 2)
return BitConverter.ToInt16(b,0);
else
return b[0];
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
|
"Hi dear"
|
|
|
|
|
Hi, trying to encrypt something using RSAServiceProvide. I have two problems.
1. Bad data when decrypting.
(1) In prototype, RSA_Server instance in decrypting side and encrypting side is the same instance. Of course, this will change later.
RSAServiceProvider RSA_Server;
(2) On encrypting side:
RSA_Server = new RSACryptoServiceProvider();
encryptedbuffer = RSA_Server.Encrypt(
databuffer,
false);
NOTE: At first I was suspecting that databuffer is than 5 bytes. But I get same problem after I trimmed databuffer down to one bytes. Anyway, here's quote from MSDN:
"The length of the rgb parameter is greater than the maximum allowed length. If the fOAEP parameter is false and the encryption is performed on a computer with the high encryption pack installed, the maximum length of the rgb parameter is 16 bytes. If the high encryption pack is not installed, the maximum length of the rgb parameter is 5 bytes."
(3) On decrypting side:
plaintext = RSA_Server.Decrypt(encryptedbuffer, false);
2. How can I retrieve private key from RSAParameters instance? I need to "publish" my public key - not the entire RSAParameters. Here's code from MSDN:
//Good. PublicKey and "Exponent" are both byte array.
byte[] PublicKey = {214,46,220,83,160,73,40,39,201,155,19,202,3,11,191,178,56,
74,90,36,248,103,18,144,170,163,145,87,54,61,34,220,222,
207,137,149,173,14,92,120,206,222,158,28,40,24,30,16,175,
108,128,35,230,118,40,121,113,125,216,130,11,24,90,48,194,
240,105,44,76,34,57,249,228,125,80,38,9,136,29,117,207,139,
168,181,85,137,126,10,126,242,120,247,121,8,100,12,201,171,
38,226,193,180,190,117,177,87,143,242,213,11,44,180,113,93,
106,99,179,68,175,211,164,116,64,148,226,254,172,147};
byte[] Exponent = {1,0,1};
//Create a new instance of RSACryptoServiceProvider.
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
//Create a new instance of RSAParameters.
RSAParameters RSAKeyInfo = new RSAParameters();
//Set RSAKeyInfo to the public key values.
RSAKeyInfo.Modulus = PublicKey; <--- OKAY, that's your public key.
RSAKeyInfo.Exponent = Exponent; <--- what da? Is this your private key?
//Import key parameters into RSA.
RSA.ImportParameters(RSAKeyInfo);
I need to pass encrypted data + RSA public key to decrypting side.
Thanks.
|
|
|
|
|
hope someone is reading the thread.
QUESTION 3:
Is RSAParameters serializable? can I send it via tcp channel as byte array?
Thanks.
|
|
|
|
|
Hi,
Can you tell me that how can I prevent a C++ class from being inherited by any other class. In C#, we have the keyword "sealed" and "final" in Java.
Do we have any keyword in C++ to avoid inheritance for a class?
Regards,
shankar.
SRI SANKARADOSS.
|
|
|
|
|
There's no such word, but there is a workaround:
- Make the constructor(s) private
- Add a public static method to return a new instance of the class.
Regards,
Alvaro
Hey! It compiles! Ship it.
|
|
|
|
|
Hi everybody,
as You may know there are avaible two versions of UDDI registers. Microsoft implemented both and developped kits (UDDI SDK). In my application I use such kit to interact with UDDI register. I must decide at write-time to which one I add reference. But I want to decide about it at run-time because some of registers work with both UDDI versions and some don't.
Any suggestions?
thanks for help
Lukas
|
|
|
|
|
I like to start a program (exe-file) with an object I pass to. Both programs, the caller and the called are written in c#. Any ideas?
|
|
|
|
|
|
As suggested, I also think that it "smells" like a bad design. Unless you have strong motivations, you should change the design, and make a shared DLL used by the two programs.
But, assuming you already exhausted this option, and can't change the design, you easier options are:
a. You can serialize the object to disk or to a socket, so the second process can deserialize it.
b. You can use remoting and pass the object to the second process.
If your object is small (< 128 bytes), you could also make a string representation of it (or serialize it to a base64 stream) and pass the resulting string as the command line argument.
You can do it on anything you choose - from .bat to .net - A customer
|
|
|
|
|
Hi. I want to implement a program that sends 1 as a numerical value if a checkbox is checked and zero otherwise. So I read MSDN.
I read from MSDN that:
"The Boolean class implements true as the integer, one, and false as the integer, zero. However, a particular programming language might represent true and false with other values. "
I did this in C#:
Checkbox1.checked.GetHashCode();
I get the 1 and 0. But is this safe? I'm worried about the part where it says "However, a particular programming language might represent true and false with other values. " I'm afraid this might cause any side effect. Any ideas what Hashcode is?
"To teach is to learn twice"
|
|
|
|
|
|
when it says some languages represent it different, most, frmo my experience, either follow the C# convetion or use 1 to represent true and 0 or less as false (e.g. C). You can easily convert bools to ints using Convert.ToInt32(value) .
However Convert.ToBoolean will acturately convert 1 to true and 0 to false, but when i tried it, converted -1 to true.
|
|
|
|
|
freshthinking wrote:
0 or less as false (e.g. C).
Whoa there! In C (and most other languages), false is 0; anything that is not zero is considered true. That is why -1 was converted to true when passed into Convert.ToBoolean.
James
At Jethro Tull's August 28, 2003 concert Ian Anderson mentioned that the group would be performing a medley of title tracks. The songs were "Songs from the Wood", "Too Old to Rock and Roll; Too Young to Die"; and from the Heavy Horses album, "Stairway to Heaven".
|
|
|
|
|
Exactly. Amazing how people get confused by 'bool'
But wait, what the heck is the connection between GetHashCode and bool? Is the original poster insane or is it me?
|
|
|
|
|
I think the original poster was just looking for something on the Boolean class which returned an int, and GetHashCode just happens to do that.
I've replied with what I hope we can agree is a better way of doing what was wanted.
James
At Jethro Tull's August 28, 2003 concert Ian Anderson mentioned that the group would be performing a medley of title tracks. The songs were "Songs from the Wood", "Too Old to Rock and Roll; Too Young to Die"; and from the Heavy Horses album, "Stairway to Heaven".
|
|
|
|
|
Actually, m not goin insane. hehhe. I was actually looking for a way to convert the boolean method without resorting to using Convert. Anyway, m just exploring C#. Thanks anyway!
|
|
|
|
|
daljv wrote:
Any ideas what Hashcode is?
GetHashCode is used to provide a value called a 'hash' for classes like System.Collections.Hashtable . These classes use that value to create a collection which can grow but still retain a fast look-up to get the proper value. A hash table is also called a Map by some people because you can map one value on to another.
For example, you can use a Hashtable to map a string representing the name of a customer onto an object that contains more information about that customer. Hashtable internally calls GetHashCode on the string so that it can find the customer object quickly.
Rather than calling GetHashCode on the Checked property you could just use the ?: operator.
Checkbox1.Checked ? 1 : 0;
That basically expands out to,
if( Checkbox1.Checked )
return 1;
else
return 0; HTH,
James
At Jethro Tull's August 28, 2003 concert Ian Anderson mentioned that the group would be performing a medley of title tracks. The songs were "Songs from the Wood", "Too Old to Rock and Roll; Too Young to Die"; and from the Heavy Horses album, "Stairway to Heaven".
|
|
|
|
|
Hi, I have a problem:
I have an .NET application that uses Crystal Reports as reporting tool. I need to filter records. The problem is that I have just dataView.RowFilter string but Crystal reports do not accept it becouse they have their own syntax for selecting records.
Is there any way i can give normal MS SQL syntax string to filter records? (I mean where clouse)
Or I need to create translator from SQL syntax to Crystal syntax?
Do not offer to use ADO.NET datasets, they work very slow.
Thanx
|
|
|
|
|