|
SJ_Phoenix wrote:
if(string == "something"){ }
This is not the best method for checking a string. Instead, do something below:
string s = "Nick";
if(string.Compare(s, "Nick") == 0)
{
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
To add, you can use String.Compare to perform case-insensitive searched by adding a bool as the third parameter. By default, this performs a comparison using the invariant culture, but you can specify a specific culture to perform a comparison using the text rules for that culture as well.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I think you're all missing the point.
He wants to evaluate a string to see if its contents are a valid C# code snippet, not a specific piece of text.
Not that I know the answer, mind you, but I thought I'd at least try to get the guy some help.
If it were me, I'd be looking at on-the-fly code compilation and let the compiler to the parsing.
Grim (aka Toby) MCDBA, MCSD, MCP+SB
SELECT * FROM user WHERE clue IS NOT NULL
GO
(0 row(s) affected)
|
|
|
|
|
|
YES YES YES! Thank you.
I exactly want to do what Mr. Grim says. I am using a textbox where users have to enter a string, I need to validate if it is a valid C# statement. And is it possible to display the . (dot) operator menu..
Help PLZ
_____________________________________________________
Yea! I could be wrong...
|
|
|
|
|
You will have to place the text into the context, and then compile it (via CodeDomSnippet or something). where are you planning on using the code?
top secret xacc-ide 0.0.1
|
|
|
|
|
Ok but how do you compile the code with .. CodeDomSnippet..?? & I'm trying to use the validation for a textbox. Users have to enter statements & they should be validated to true if they are valid C# statements.
HELP
PLZ
_____________________________________________________
Yea! I could be wrong...
|
|
|
|
|
What you wanna do is way more complex than you can handle right now, I suggest you learn a bit more beforetrying to attempt something like this. A good understanding of parser and lexer technologies is essential.
top secret xacc-ide 0.0.1
|
|
|
|
|
Thanx for clearing that up..
Recources please!
_____________________________________________________
Yea! I could be wrong...
|
|
|
|
|
Hi folks
I've got a new Problem using the UIPAB v2.0
I tried to implement a Wizard, but i didn't found any method for navigation nonlinear. The navigation graph wich is presented by the examples are only linear, but i have the problem that the following form depends on data wich is given in the wizard-page. So there are maybey two or more pages wich can follow another page.
Are there any possibilties to controll the navigation dependending on the data?
****************************
phoenixcp
Free Win2k and support Linux
****************************
|
|
|
|
|
If you have a problem with a specific product, you need to consult support for that product (or if it's from an article here on CodeProject, ask in the article's message board at the bottom of the article).
If you have a problem specific to C# (like how to marshal data, if necessary, using UIPAB), this is the place to ask.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Dear all:
My Org. use a Encryption for its passwords & I have to obey it too in my App to be the same as all other App. in Org.
In this Encryption we use entered values's Ascii & ...
I can get the ASCII value of Chars as:
(int)'A' = 65 & vise versa (char)65 = 'A'
but since I use Farsi(Arabic) Chars it gives me Unicode of that char like:
(int)'ش' = 1588
Is there any way to use its ASCII & not unicode?!
Of course, I can use change Farsi entered Chars to English to get its ASCII but some of Encrypted Chars are not English letters & I have to use them!
I realy need ur help bc all App. is waiting for that Login part
Thanks in Advance & Hope to hear from u ASAP!
Always ,
Hovik Melkomian.
|
|
|
|
|
First you need to understand that all characters (and hence, all strings) are treated as Unicode in .NET (strings are even stored as Unicode in the assembly).
You can, however, use the Encoding class with the proper codepage.
See, ASCII is actually 7bit characters. Anything over 127 requires a codepage in order to resolve the symbols correctly.
To get the codepage for Farsi, you can either refer to it by the codepage, or if you don't know it do something like this:
CultureInfo ci = new CultureInfo("ar");
int codepage = ci.TextInfo.ANSICodePage; If you read the class documentation for the CultureInfo class in the .NET Framework SDK, you can find the LCIDs and culture name abbreviations (like "en-US" for "English (United States)"). For a non-regional Arabic language, you can use the LCID 0x01 (1).
So, to get an Encoding for that codepage, do this:
Encoding enc = Encoding.GetEncoding(0x04e8);
byte[] buffer = enc.GetBytes(yourFarsiString);
foreach (byte b in buffer)
Console.Write(b.ToString("x2"));
Console.WriteLine();
Here's an example of decoding a Unicode string I assume says "Hello" (in Farsi) into ANSI characters using the Farsi codepage:
using System;
using System.Globalization;
using System.Text;
class Test
{
static void Main()
{
CultureInfo ci = new CultureInfo("ar");
int codepage = ci.TextInfo.ANSICodePage;
Console.WriteLine("Using codepage 0x{0:x4}", codepage);
string str = "\ufeed\ufee0\ufe8e\ufeeb";
Console.WriteLine("Decoding " + str);
Encoding enc = Encoding.GetEncoding(codepage);
byte[] buffer = enc.GetBytes(str);
foreach (byte b in buffer)
Console.Write("0x{0:x2} ", b);
Console.WriteLine();
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Dear Heath Stewart:
Thanks for ur fast response & sorry for my delay! Actually I was working to fix my problem & I did as:
byte[] ubuf = Encoding.Unicode.GetBytes(c.ToString());<br />
Encoding enc = Encoding.GetEncoding(1256);<br />
byte[] abuff = Encoding.Convert(Encoding.Unicode, enc, ubuf); (But Tnx for ur code)
But now I need the opposite of that!
I mean I have ASCII now & this time I wanna have its character.
As u know values r not same since I have to make it as same as other softwares in my Office.
Example:
(char)211 = 'Ó' witch is wrong & should be 'س' Unicode 1587
Please help me about this, witch is highly appreciated!
Again tnx for code & Hello Sample;) & Sope to hear from u ASAP.
Always ,
Hovik Melkomian.
|
|
|
|
|
Then reverse what I did. This is a simple problem and you need to read about the Encoding class. I've given you plenty of information. You just use Encoding.Convert to convert from the Arabic codepage to Unicode.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ok this is what I done.
Encoding ascii = Encoding.ASCII;<br />
Encoding enc = Encoding.GetEncoding(1256);<br />
<br />
byte[] asciiBytes = enc.GetBytes("س");
And I have 211 (ASCCI of unocde 1587) witch ok!
Also I have array of bytes in ASCCI mode & I wanna convert them in Unicode 1256.
byte[] unicodeBytes = Encoding.Convert(ascii, enc, asciiBytes);
Now I should have array of bytes in Unicode 1256.
And I should changethem in Strig mode so I do
char[] asciiChars = new char[ascii.GetCharCount(unicodeBytes, 0, unicodeBytes.Length)];<br />
ascii.GetChars(unicodeBytes, 0, unicodeBytes.Length, asciiChars, 0);<br />
string asciiString = new string(asciiChars);
But it gives me ? char & not 'س' Unicode 1587
Did I miss any?!
Tnx for ur time.
Always ,
Hovik Melkomian.
|
|
|
|
|
1587 has nothing to do with Unicode, mind you. It's an ASCII codepage. What you're doing is converting from ASCII (for a particular codepage) to Unicode.
If you get ? or a hollow block character, it's because the font doesn't have that character. You need to use a different font, like Tahoma or Arial Unicode MS. Unicode (and any character set, for that matter) only defines characters - not fonts.
If you're trying to print this to the console, it won't work (currently) because the console uses fixed-width fonts of a certain format.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
but already all my form's obj r in Tahoma!
I know 1587 has nothing & I just write it to say what I wanan show!
Doest my code correct to change from ASCII to Unicode or not?!
Always ,
Hovik Melkomian.
|
|
|
|
|
A glyph for character \u0633 (1587) does exist in the Tahoma font, hence the ? like I said earlier. If there's no glyph for a particular font, then you'll have to use a different font or use an image with the text, but then it's pretty static.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I Get a datatable from Database's someting table at first, then, some time after, I Get a datatable from database's same table.In my programe,I want to know this table's all records if changed. Do have some good method?
|
|
|
|
|
You can use DataSet.Merge(DataSet, bool) to merge the two DataSet s and preserve the changes. You then call DataSet.GetChanges on the same DataSet you called Merge on, and enumerate through the table(s), then enumerate the rows and check DataRow.RowState .
If you call DataSet.AcceptChanges or DataTable.AcceptChanges , these changes will be lost (the rows are resolved according to their state). Calling DataAdapter.Update on the DataSet or DataTable will call this method automatically.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have an idea to submit an article about a system to license components. Since I have looked all over and have not been able to find much of real use in this area elsewhere I figured that I might as well share the knowledge a bit here since I have gotten so much from the site.
My problem is this… The code has a few issues (for lack of a better term ) that I just cannot seem to get ironed out. Not that I am not trying mind you, I just have not been able to figure it out yet. The question is this. Is it considered good (or just even ok) form to post an article that has 'issues' in hopes that:
1 - Others will benefit form the code
2 - Others might help locate what the heck I am doing wrong?
I hate to add to the chaff of the site by posting an article that will just end up confusing people in the long run.
Paul Watson wrote:
"At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.
|
|
|
|
|
As a former CodeProject editor (didn't have the time anymore) and current Protector, I can assure you there's much worse articles. I'd say go ahead and post it, but make sure you point out what the problems are. Don't forget to update your article (with a history of changes at the bottom; read through some existing good articles for examples) when you've solved it and make sure you read comments in your article's forum (you should get an email automatically when anyone posts a message to your article's message board).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I've subclassed two classes inside classA. Theses subclasses are derived from classA. There are some virtual functions in classA with their implementation defined in those subclasses. Client can only see classA. Instances of classA will be created by a class factory. On basis of parameters passed to class factory, the factory creates new objects of subclasses and returns them to client. Following snippet demonstrates the idea.
<br />
public class classA<br />
{<br />
<br />
<br />
<br />
internal class subclass1 : classA<br />
{<br />
<br />
}<br />
<br />
internal class subclass2 : classA<br />
{<br />
<br />
}<br />
} <br />
1) I want to run subclass1 objects into COM+ transaction. Is it possible because client never sees subclass1 although it uses subclass1. If possible how ??
2) Is it a good practice to do things this way. The idea behind was to provide client smplicity of using one class while acheiving the logical seperation at the backend for developer's ease.
Thanks in advance,
Regards,
Hatim Ali.
|
|
|
|
|
In the System.Dialognise namespace there are many classes helping detect system error.
Now i have a big problem: Does there have a possibility to detect error from application software ?
For example, can i get a message while my office word.exe facing an error(any type of error) ?
|
|
|
|