Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to put check to validate textbox that input value must not be similar to the values already present in database. Like:
if there is value with text "Hello" in database then user must not be allowed to save value either he writes:
Hello
HELLO
hElLo
HeLLO
Hello etc
I followed this http://www.dotnetperls.com/string-isupper-islower but as i am new to c# so have little confuse that how to match above defined words as all are same words Hello
I typically just convert both values (user input and stored value) to lower case when making the comparison.
Edit: if both values are in .NET, you could use String.Compare(s1, s2, StringComparison.OrdinalIgnoreCase)
Do you need to do this in code? I would suggest that you just make a unique constraint on the column and let the database handle that for you. Depending on the database you are using you may need to do a little additional work to handle the case sensitivity.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
How do you read the lines one by one if their fields are uneven and you need to know when it ends.
For example:
A;B;C;D
E;F;G;H;J
'A' is a person and 'B' , 'C' and 'D' are his friends.It goes the same for the second line I wrote.I know I could just write it with an even number of fields but I think this is a neater way to do it.
Thank you.
There are two functions that make this really easy: StreamReader.ReadLine and String.Split.
You use StreamReader.ReadLine to get the entire line of text:
string lineOfInput = reader.ReadLine();
Then, you can split on the semicolons to get all your "fields":
string[] fields = lineOfInput.Split(';');
fields[0] will contain the "person" and the rest, his "friends".
See StreamReader and Split on MSDN.
CSV files are deceptively simple. See this question, Simple csv reader?, for some details.
But I'd just use Sebastien Lorion's Fast CSV Reader from CodeProject:
http://www.codeproject.com/Articles/9258/A-Fast-CSV-Reader
All you've got to do is set the correct field separator and you're good to go. It's fast, it works well. It implements IDataReader, so it acts like a normal .Net data reader implementation.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
when using StreamReader in C# to load a txt file into a list, i assume that using a simple "If" the string's length is over a particular length, it will add it to the list. can anyone provide C# code for this? this IS homework, but it's NOT a C# class. the instructor would gladly provide this if i asked this specifically. thx.
the txt file is a dictionary of ~280,000 words, one per line. very simple move to turn into a list, but i'm wondering about getting words at least 2 characters long.
Just use LINQ to give you a subset.
List<string> lines = File.ReadLines(filename)
.Where(l => l.Length > specifiedWordLength)
.ToList();
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I was looking for RSACryptoServiceProvider helper and found two different implementations
1) http://www.cnblogs.com/WYB/archive/2008/06/19/1225704.html
2) https://github.com/robvolk/Helpers.Net/blob/master/Src/Helpers.Net/EncryptionExtensions.cs
both of them working
var encryptedBytes = myBytes.RSAEncrypt(publicKey);
System.Text.Encoding.Unicode.GetString(encryptedBytes);
returns strings like "蹩巷Ӂය馧㾵봽놶徤蕺蓷課Ϝ堲泍썳⁙䃑ക늏...."
myString.EncryptStringUsingXMLFile(publicKey)
returns strings like "AnvFFT6YpoiAyIFwl+tueZq56Zcb0B7WhBEvz5uWl...."
May be some one can explain why first one producing Chinese strings and how to change that?
What approach is better?
To answer your first question. While it may look like it is producing Chinese characters what is actually happening is it is turning a byte array into unicode. In c# typically when you want to store a byte array you convert it to base64 which is what your second example appears to return.
Your first example would become this:
var encryptedBytes = myBytes.RSAEncrypt(publicKey);
Convert.ToBase64String(encryptedBytes) // this line changed
returns strings like "AnvFFT6YKpoiAy...."
As for what is recommended, the most common is to use base64. The reasons people use base64 over unicode or UTF-8 for binary data can be found in these answers:
https://stackoverflow.com/a/201491/701062
MSDN - Convert.ToBase64String(byte[])
http://msdn.microsoft.com/en-us/library/dhx0d524(v=vs.100).aspx
MSDN - Convert.FromBase64String(string) - Useful if you need to convert back into a byte array
http://msdn.microsoft.com/en-us/library/system.convert.frombase64string(v=vs.100).aspx
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a typed dataset with a column called price, which is of string datatype. And I'm showing this via ultrgrid/datagrid
How can I show the price in number format.
For example: price ==123456
in the grid it should be like 12,354,56
Try this
var a = price.ToString("##,###,##");
Reference
Custom Numeric Format Strings!
Look at some of the related links to the right of the screen. Some of them even ask the same question as you !
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have the following code that refuses to be parsed into a date:
20130718-18:15:36.038
Does anyone know what the correct C# code is to parse it using System.Datetime.Parse() is?
Thanks.
DateTime.ParseExact("20130718-18:15:36.038", "yyyyMMdd\\-HH\\:mm\\:ss\\.fff", null);
All the format strings are found here.
As a side note, make sure you use the backslashes before the special characters to tell the code that you want to use that specific character exactly as-is instead of a system value (and the double-backslash here is C#'s escaping a single backslash). Alternatively you could do #"yyyyMMdd\-HH\:mm\:ss\.fff".
string theDate = "20130718-18:15:36.038";
DateTime tempDate = DateTime.ParseExact(theDate, "yyyyMMdd\\-HH\\:mm\\:ss\\.fff", CultureInfo.InvariantCulture, DateTimeStyles.None);