|
Thanks Ben. What I am attempting to do is the following. I need to read the file searching for specific values, "2, 4,5,6,7,8,9" at offset 653. Once a match is made with one of the values above then I need to write data from offset 1134 for 11 characters to an output file.
Now, with the filehelpers engine this is easy but I am not sure how to do this manually as the filehelpers engine lets you specify the different offsets in a class. You can then just write the specific fields as output. As I do in the below piece of code.
foreach (IvalueRev rev in res)
{
if (rev.Flag == "2" || rev.Flag == "4" || rev.Flag == "5" ||
rev.Flag == "6" || rev.Flag == "7" || rev.Flag == "8" || rev.Flag == "9")
{
sw.WriteLine(rev.HID.ToString() + "\t" + rev.Flag.ToString());
From the above, I search the file for the values as stated. rev.Flag is the flag at pos 653. Once a match is made then I write rev.HID out to an output file.
Hope this explains what I am trying to do.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Kwagga,
When you refer to values at offset 653 and 1134, are you referring to that offset in a particular line of text? In other words, do you need to read 11 characters starting from position 1134 when the character at position 653 in the line of text is 2, 4, 5, 6, 7, 8, or 9?
If so this would be how you do it (not sure if the offsets of 653 and 1134 are zero-based):
StreamWriter sw = ...;
StreamReader reader = null;
char flag = ' ';
try
{
reader = new StreamReader(filePath);
string holdLine = String.Empty;
while(!reader.EndOfStream)
{
holdLine = reader.ReadLine();
if(String.IsNullOrEmpty(holdLine))
continue;
flag = holdLine[653];
if(flag == '2' || flag == '4' || flag == '5' || flag == '6' ||
flag == '7' || flag == '8' || flag == '9')
sw.WriteLine(holdLine.Substring(1134, 11) + "\t" + flag.ToString());
}
}
catch(Exception ex)
{
<... handle the exception here ...>
}
finally
{
if(reader != null)
reader.Close();
if(sw != null)
sw.Close();
}
In order to account for what you are trying to do and not have to hold the contents of the file in memory, in the FileHelper class one alternate would be for it to have an event that could, for example, be triggered each time a row is read from file. Then, you could handle the event and process each row as it comes in, utilizing the objects that the FileHelper class provides because the event could supply the IValueRev object via a custom EventArg. It seems that there are some objects the FileHelper class creates that probably interpret the data and make it easier to work with, so it has value for the system you are working within. Perhaps the best solution is not to abondon the tool if it indeed has a valuable capability, but to expand it to be more flexible.
Keep It Simple Stupid! (KISS)
|
|
|
|
|
How should I set the DisplayMember and ValueMember properties for my ComboBox 'addressSourceComboBox' please? Here is my code:
private void PopulateCorrespondenceAddressComboBox()
{
ArrayList CorrespondenceSources = new ArrayList();
int corrCount = 1;
foreach (DebtorDataSet.DebtorRow debtorRow in DebtorDataSet.Debtor)
{
CorrespondenceSources.Add(new CorrAddress("D" + corrCount.ToString(), "Debtor " + corrCount.ToString() + " - " + debtorRow.Salutation.ToString() + " " + debtorRow.Forename.ToString() + " " + debtorRow.Surname.ToString()));
corrCount++;
}
addressSourceComboBox.DataSource = CorrespondenceSources;
}
private class CorrAddress
{
private string _source;
private string _text;
public CorrAddress(string source, string text)
{
_source = source;
_text = text;
}
public string ItemSource
{
get { return _source; }
}
public string ItemText
{
get { return _text; }
}
}
|
|
|
|
|
it's OK I figured it out:
addressSourceComboBox.DataSource = CorrespondenceSources;
addressSourceComboBox.ValueMember = "ItemSource";
addressSourceComboBox.DisplayMember = "ItemText";
|
|
|
|
|
Hi all
I have a DateTimePicker control in my windows application(c#)
am taking the selected value from the DateTimePicker to a textbox...now am getting the value
in the format of ' dd-mm-yyyy ' but i want to get the value like ' dd/mm/yyyy '...
i have given all these..
dateTimePicker1.CustomFormat = "dd/MM/yyyy";
dateTimePicker1.Format = DateTimePickerFormat.Custom;
txtdate.Text = dateTimePicker1.Value.ToShortDateString();
how can get the value like which i have mentioned...
any help is appreciatable....
thanks in advance...
|
|
|
|
|
txtdate.Text = dateTimePicker1.Value.ToShortDateString().Replace("-", "/");
That should do the trick.
Kinda ugly, but it should work.
Kristian Sixhoej
|
|
|
|
|
Thanks Kristian...
It wrked well....
|
|
|
|
|
Kristian Sixhoej wrote: Kinda ugly, but it should work.
This is really ugly. What's wrong with using ToString() with a proper format specifier?
modified 12-Sep-18 21:01pm.
|
|
|
|
|
You have half the answer yourself - you know the format and how to specify. What you may not know is that dateTime has an override of ToString which can take this format.
txtdate.Text = dateTimePicker1.Value.ToString("dd/MM/yyyy");
|
|
|
|
|
This should work
txtdate.Text = dateTimePicker1.Value.ToString("dd/MM/yyyy");
Hope this helps
|
|
|
|
|
hi....
actually am doing a simple application using
" WCF Service Application " & " ASP.NET Web Application "..........
my code is correct and everything is perfect..
but when i run, it displays the following message....
" An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue "
when i run in the morning the output is displayed..but after sometime , when i run it shows that message.....
whats the solution...??...
|
|
|
|
|
Looks like you are running out of resources.
Just a thought: Are you cleaning up the resources you are using? Do you have a lot of objects that implement the IDisposable interface that you are not disposing correctly?
|
|
|
|
|
So I read a file and that file has like 9k lines.
the lines look like this(well it might not fit here, but is on a line only):
A:"extatic" A:"extatici" A:"extaticul" A:"extaticului" A:"extaticii" A:"extaticilor" A:"extatică" A:"extatice" A:"extatica" A:"extaticei" A:"extaticele" A:"extaticelor"
And I use textreader in c# to find a char in that text for example "extaticele" here.
What I want is to extract if I found the char on that line the first char on that line. In this case "extatic" - but without "" of course and paste it in a text file.
I dont know exactly how to work with find space so I want your help...cause I thought I'd find the first space in the line then take the index and with the index 0 of the line to extract "A:"extatic" ".
Then remove the "A:" and the ".
I saw somewhere an example with myString.find("") , but I can't find the "find" I might need a namespace.
|
|
|
|
|
In .Net, reference types are also objects. That means that most of the commands that you are looking for are present in the string itself. You can play with stuff like:
String test = "abcd";
int index = test.IndexOf('b');
String test2 = test.Substring(index);
// etc...
There are plenty of methods on the string object. There are also static methods in the String class, like for example:
String.Compare(string1, string2...)
Last but not least, the namespace you are looking for is simply System.
Jean-Christophe Grégoire
|
|
|
|
|
I use that namespace, but there is no mystring.Find - I just want to find the index of the first space in a line
|
|
|
|
|
ipstefan wrote: I use that namespace, but there is no mystring.Find - I just want to find the index of the first space in a line
int index = myString.IndexOf(" ");
Kristian Sixhoej
|
|
|
|
|
Yep I thought at that option too earlier and it works...
I solved my problem with indexes and substrings.
Thanks
|
|
|
|
|
You're welcome
Kristian Sixhoej
|
|
|
|
|
hi ipstefan,
my sugession is read contents of file sequentially and check whether the character u r reading is ", it it is then take all next characters untill next " apprears so u can get each character between "". From these chars u can make a string by using + operator and later it can be pasted where u want.
Or as u mentioned myString.find() method, i hope find method is custom method not in framework. Instead, u can use following method of class String.
String myString = "abcd";
String cutString = myString.Substring(0,3);
the value of cutString will be 'abc' . Try to use this method. Ok..
Hope it will help u.
|
|
|
|
|
Dear all,
I am working on C# project, which need to digital sign on all data (string DataType). I have .pfx (X509) file already (contain public key + private key). Is there anyway to pass the private key + public key in .pfx file to DSA, to create digital signature ?
Below is the code in JAVA, which I think use DSA in C# may create the digital sign exactly this java code.
Many thank if you can help.
//---------------------- JAVA DIGITAL SIGN CODE ---------------------
private static void readPrivateKeyAsClassPath() {
try {
// Read key
InputStream fis = SignatureDegist.class.getResourceAsStream("/"
+ keyFile);
ObjectInputStream ois = new ObjectInputStream(fis);
priv = (PrivateKey) ois.readObject();
ois.close();
} catch (Exception e) {
}
}
/**
* @param filename
* @throws FileNotFoundException
* @throws IOException
* @throws ClassNotFoundException
*/
private static void readKeysPrivateKey(String filename)
throws FileNotFoundException, IOException, ClassNotFoundException {
if (priv == null) {
setKeyName(filename);
readPrivateKeyAsClassPath();
}
}
private static byte[] sign(InputStream reader, String sigAlg)
throws Exception {
Properties pro = new Properties();
pro.load(SignatureDegist.class.getResourceAsStream(CONFIG_KEY_FILE_LOCATION));
if (priv == null) {
readKeysPrivateKey(pro.getProperty("filename"));
}
Signature sig = Signature.getInstance(sigAlg);
sig.initSign(priv);
byte[] dataBytes = new byte[1024];
int nread = reader.read(dataBytes);
while (nread > 0) {
sig.update(dataBytes, 0, nread);
nread = reader.read(dataBytes);
}
;
return sig.sign();
}
private static byte[] sign(String datafile, String sigAlg) throws Exception {
return sign(new ByteArrayInputStream(datafile.getBytes()), sigAlg);
}
public static void main(String[] unused) throws Exception {
// Generate a key-pair
String accountIdSource = "123100003456";
String accountIdDest = "456100014123";
long value = 100;
String desc = "transfer";
String contactID = "NHK-XJ";
String typeId = "00";
StringBuffer buffer = new StringBuffer();
buffer.append(accountIdSource);
buffer.append(accountIdDest);
buffer.append(value);
buffer.append(desc);
buffer.append(contactID);
buffer.append(typeId);
byte[] degist = sign(buffer.toString(), "SHAwithDSA");
System.out.println("Signature degist :: " + degist);
System.out.println("Signature degist :: " + new String(degist));
Base64 decoder = new Base64();
System.out.println("Signature degist :: " + new String(decoder.encode(degist)));
System.out.println("Signature degist :: " + new String(decoder.encode(new String(decoder.encode(degist)).getBytes())));
|
|
|
|
|
Hello,
a 3rd party supplier informs me their components are compiled for "ANY CPU", so they'll run x86 or x64 based on the platform to which they're deployed. This confuses me a bit; I had thought a select choice of x64 compilation would ensure the best performance, which is why so many companies these days deliver product-installers for both x86 and x64. But if I'm to take his word for good measure, there's no need (at least .net-wise) to ever compile to a specific CPU architecture, as the "ANY CPU" option will always ensure the assemblies run as fast as possible, given the host CPU?
Hope someone might be able to clarify on this,
thanks in advance,
Morten
|
|
|
|
|
The Any CPU option is not optimised for a specific processor. It will give you good general all round performance that works across any of the target processors. If you absolutely must have all the performance you want then target the appropriate processor.
[ADDITIONAL]
First Addition::
There seems to be a lot of confusion about this. MSDN says one thing. The C# compiler command line help says another.
Second Addition:
See Guffa's post as he links to an article that explains exactly what is happening, and contradicts the MSDN article I used as the source of my original answer.
[/ADDITIONAL]
modified on Friday, January 9, 2009 1:24 PM
|
|
|
|
|
Hello Colin,
this was also my impression. Thanks a lot for clearing this up for me.
best,
Morten
|
|
|
|
|
harleydk wrote: Hello Colin,
this was also my impression. Thanks a lot for clearing this up for me.
Then your impression was also wrong.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Colin Angus Mackay wrote: It will give you good general all round performance that works across any of the target processors. If you absolutely must have all the performance you want then target the appropriate processor.
That is not correct. The IL code generated is the same regardless of which CPU target you specify.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|