|
I am converting a java app to C# and the passwords were encrypted with an algorithm written in java which uses the following to convert from a char to an int. Does anyone know the equivalent for C#?
<br />
int result = Character.getNumericValue('b');
The 'equivalent' in C# returns different results...
<br />
double d12 = Char.GetNumericValue('b');
or
<br />
int i12 = Convert.ToInt32('b');
What is the cause (other than java being a joke!) and how can I get the correct result?
Thanks,
ed
Every time I walk into a singles bar I can hear Mom's wise words: "Don't pick that up, you don't know where it's been!"
|
|
|
|
|
I can't think of any reason, in any context, for 'b' to be '11'. I know capital A is 65 in ASCII, I'm not sure if lowercase b is ASCII 98. In any case, why don't you just subtract 87 ? Or is it not just for lowercase letters ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
I was about to do that then the meeting started so I fired off the question to see if anyone had run across it. I'm going to try that in the morning and walk the keyboard and see if everything fits. If not...do some sort of lookup.
Java!!
Thanks,
ed
Check out the stir on theserverside.com[^]!!
|
|
|
|
|
Have you checked out MS's Java to C# convertor? Last time I checked it was still in early beta and didnt do such a good job (think it only supports Java 1.1), but it definately looked handy
"There are no stupid question's, just stupid people."
|
|
|
|
|
You are just showing how little you know about Java. I don't know much either, but I can read the reference doc.
In short, Character.getNumericValue returns a code from an internal vm table known as the UAT (Unicode Attribute Table). As a result, this returns what you may call "weird" numbers.
To get the unicode from a char, you just need to cast it.
int unicodevalue = (int) 'b';
PS : Java being a joke?
Ha ha!!!!
How low can you go ? (MS rant)
|
|
|
|
|
Hi All,
Is it possible to create an Access DB "on the fly" using ADO? If not is there any other method?
Thanks,
J.
|
|
|
|
|
Wrong forum! Post in SQL/ADO forum.
"There are no stupid question's, just stupid people."
|
|
|
|
|
Here's an answer from google
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
|
I wanted to do just that without having to include an interop assembly. I just created a blank db in Access and added it as a resource to my project. Then whenever I wanted to create a new blank db I just created a new file and streamed out the binary resource data for the mdb. Probably wouldn't get your program a "Designed for" Windows sticker, but it works.
|
|
|
|
|
Hi all,
Does anyone have an idea how to create charts in C#?
Or of any tutorials on how to create them?
Thanks,
J.
|
|
|
|
|
Yes, I've done a series of articles on GDI+, they are in C++ but the methods are the same in C#.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Does anyone know how I can find out the SQL Server type of a db column from within C#. I know that when I obtain data in a DataTable, each of the DataColumn objects contain information about the column including the column name and the data type, however, the type that it provides is a System.* C# type. Is there any way to determine the SQL Server type name (e.g. int, smallint, etc.) programmatically?
TIA
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Hi
I presume you have a DataSet to transfer the data? Well, just look in there
"There are no stupid question's, just stupid people."
|
|
|
|
|
I've been looking in there through the debugger as well as in the DataTable and DataColumn and I don't see anything that would tell me the type or the length of the individual columns. Do you know of something more specific?
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Your dataset contains the mapping from SQL types to .NET types, if you dont have a dataset (which I doubt), just get one of the data adapters auto generate u one. Then double click that file (the .xsd file) and it will show the equivalent SQL types. For the length of each type (of each parameter), that too get auto generated if you are using stored procedures.
Hope this helps
"There are no stupid question's, just stupid people."
|
|
|
|
|
You say that "Your dataset contains the mapping from SQL types to .NET types...". I do have a DataSet, I just don't know where this mapping is that you are referring to. What member of the DataSet contains this information? You understand that I want to obtain this info programmatically, right?
Thanks again.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
perlmunger wrote:
You understand that I want to obtain this info programmatically, right?
No, but i do now
<dataset instance="">.<tablename>.Columns["Usersorwhatever"].....oh damn I have no idea, where that takes place... You can find out the .NET types, so I assume the cast from SQL to .NET is auto, inserting values u need the SqlType and width though, so I'm not sure how this is done. I will look tomorrow, I need some desperate sleep
"There are no stupid question's, just stupid people."
|
|
|
|
|
I would avoid to use the dataset because at this point they have already done some type mapping (either CTS, or XSD).
Here is the code for retrieving the internal SQL Server data type for any database table columns :
DataTable oTable = new DataTable();
SqlDataAdapter oAdapter = new SqlDataAdapter("SELECT * FROM INFORMATION_SCHEMA.COLUMNS", m_oConnection);
This stores the result of the system query in oTable. Then you just need to lookup the rows of this table. Interesting columns are of course "COLUMN_NAME" and "DATA_TYPE".
If you have SQLServer installed, I guess this kind of things should be known by you a million times already, because you can see these things in the SQL Enterprise manager GUI.
How low can you go ? (MS rant)
|
|
|
|
|
I finally found a similar answer on google this morning. I am new to SQL Server, so I had no idea. Thanks for your help.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
I'm not sure what is going on here, but I hope there's someone who knows why this happens. Basically, I have a base class and an inherited class, something like this:
public abstract class Base {}
public class Inherited : Base {}
I also have a class that populates inherited objects called ObjectBuilder. It is a singleton and it has a method called PopulateObject. Here is the code to do what I want:
Inherited i = new Inherited();
ObjectBuilder ob = ObjectBuilder.GetInstance();
ob.PopulateObject( ref i );
The problem is that the signature for PopulateObject takes a ref to Base. If I understand the is-a relationship properly, doing so should work and in fact, when I remove the 'ref' keyword from the declaration as well as implementation, it builds fine. It just won't work properly because it is at that point passing a copy (isn't it?). What is going on here? Why will it build without error when I pass a copy, but fails when I pass by reference?
Any help would be greatly appreciated.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Which error message is your compiler giving?
lazy isn't my middle name.. its my first.. people just keep calling me Mel cause that's what they put on my drivers license. - Mel Feik
|
|
|
|
|
See below...
The best overloaded method match for 'DataNamespace.ObjectBuilder.PopulateObject( ref DataNamespace.Base)' has some invalid arguments
'Argument '1': cannot convert from 'ref DataNamespace.Inherited' to 'ref DataNamespace.Base'
Thanks.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
You are infact passing by reference by default unless your base class is infact of a value-type!
"There are no stupid question's, just stupid people."
|
|
|
|
|
I went ahead and tried to run my app without the ref parameter and it worked--which led me to the same conclusion. I looked back at my Programming C# book (Oreilly) and sure enough, the example where he is using this is with value types. Oy!! People who think that C# and Java are the same are smoking crack. I like C# better because you can pass a value type by reference if you want to(in java you have to use the Integer, Double, etc. classes to do so). Thanks for your help.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|