|
Hello,
I have a strange problem. I have to write a regular expression which should match a line which is a comment (//) in a source file. I'm using Expresso to test my expressions. It is not complex, //.+?\n . When I copy from the file and test it with expresso it works. But when I read the file in a string in my program there are no matches found. I copy the content of the string in Expresso and it also finds nothing. Can you help please?
Thanks
|
|
|
|
|
What's the string ? Have you tried copying a string from Expresso into your file ? ( I've had a sitation with some characters where unicode has a couple that look the same, and I get the wrong one ).
Also, make sure your regex settings are the same as the ones being used in Expresso.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
The string is the files content. When I copy it from the file and paste it in Expresso it is formatted, but when I paste it from the program's string it is not but the text contains \r\n . I try the following //.+?\r\n , but it doesn't work, expresso selects the whole string and not the different comment lines.
|
|
|
|
|
"// EditReportsDlg.cpp : implementation file\r\n//\r\n\r\n#include \"stdafx.h\"\r\n#include \"resource.h\"\r\n#include \"SPSystem.h\"\r\n#include \"EditReportsDlg.h\"\r\n\r\n#ifdef _DEBUG\r\n#define new DEBUG_NEW\r\n#undef
This is a part of the string. The expression \r\n doesn't return matches. Could you explain why?
Thanks
|
|
|
|
|
Ooops,
very dumb on my part. I should use \\r\\n.
|
|
|
|
|
I'm copying the input I give to regex.Matches and regex.Pattern in Expresso and get match results, but not in my program, the matchcollection object's count property remains 0. Any suggestions?
|
|
|
|
|
Perhaps post the string and the code, so I can have a look at it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi All,
Whats the best way to draw graphics to the console. I am looking at drawing a complete interface and having controls. Something similar to the Norton Ghost Command prompt interface.
I understand that this is a big project and it is most likely beyond my capabilities as a programmer, but if anyone can point me in the right direction to get started I would be most thankfull.
Timbobsteve
|
|
|
|
|
Can I ask why you would want to build such an archaic interface in the age of Windows and Unix/Linux GUI's?
I mean, they do all of the work for you. Unless someone still has a library for this laying around, you're going to build this from scratch. It will probably take more time to build the interface than it will to build the app that's going to use it. Is a DOS interface really a requirement?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
No Not really..... but damnit it would be fun to do!
|
|
|
|
|
Hi,
I am new to COM and .NET development. One of our client gave as Interface definitions as MIDL file and We are trying to develop the COM server using .NET framework using C#. I am wondering what is the right approach. Any help would be greatly appreciated.
Thanks,
Akth
|
|
|
|
|
Although you can create COM components in C#, I am pretty sure they do not use MIDL. However, the MIDL file gives you the interface you need to provide, so just use it for that. assuming they know you're doing it in C#, and not expecting it to be C++.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi Christian,
Thanks for your response,
Exactly the same way I am trying to do, Creating C# interface from the MIDL file but some of the data type like DWORD, BYTE, I could not find a way to define in C# using MarshalAs attribute. and also enumerations created from C# prefix the each enumeration value with name
e.g
enum A{
A1,
A2
}
is converted as
enum {
A_A1,
A_A2
} A;
but I need to expose the C# interfaces, methods, enumerations exactly defined in MILD file, because other people also developing server using the same MIDL.
Please let me know, how I can resolve this problem.
Thanks,
Kuthbul
|
|
|
|
|
DWORD == unsigned int
BYTE == unsigned char.
any type that is all captials is a #define in Microsoft C++. The easiest thing is, open a C++ project, type in the type and hover the mouse over it to find out what it is.
Akth wrote:
enum A{
A1,
A2
}
is converted as
enum {
A_A1,
A_A2
} A;
I'm not sure what you can do here, because enums in C# are always a class, and I've never done this conversion, so I don't know if you can hack it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hey guys,
got a friend who is still stuck on vb6(says he loves it ) anyhow he passed me some code that i need to convert, i got it to .net with the VS.net03 tool. But now i need it to C#, i'm not a vb programmer so i'm struggling to understand why it isn't working right. i've tried using a few different code converters but they all fail!
I've enclosed the code... any help is auesome.... oh, and anything quick is even better. My deadline got bumped from next week to tomorrow am. (which is why i had my friend "help" me.)
k,
one more thing.. it WILL run in vb.net once i upgraded it from vb6, but i can not get it to compile in C#!
'UPGRADE_NOTE: Text was upgraded to Text_Renamed. Click for more: 'ms-help:
Private Function Crypt(ByVal Text_Renamed As String, ByVal Key As String) As String
Dim KeyLen, i, KeyPtr As Integer
Dim KeyChr, TextChr As Short
KeyLen = Len(Key)
For i = 1 To Len(Text_Renamed)
TextChr = Asc(Mid(Text_Renamed, i, 1))
KeyChr = Asc(Mid(Key, KeyPtr + 1, 1))
Mid(Text_Renamed, i, 1) = Chr(TextChr Xor KeyChr)
KeyPtr = ((KeyPtr + 1) Mod KeyLen)
Next i
Crypt = Text_Renamed
End Function
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
txtText.Text = CStr(Now)
txtPath.Text = VB6.GetPath & "\DateTest.bin"
End Sub
just in case it helps here is the vb6 code...
Private Function Crypt(ByVal Text As String, ByVal Key As String) As String
Dim i As Long, KeyLen As Long, KeyPtr As Long, KeyChr As Integer, TextChr As Integer
KeyLen = Len(Key)
For i = 1 To Len(Text)
TextChr = Asc(Mid(Text, i, 1))
KeyChr = Asc(Mid(Key, KeyPtr + 1, 1))
Mid(Text, i, 1) = Chr(TextChr Xor KeyChr)
KeyPtr = ((KeyPtr + 1) Mod KeyLen)
Next i
Crypt = Text
End Function
Private Sub Form_Load()
txtText.Text = Now
txtPath.Text = App.Path & "\DateTest.bin"
End Sub
Dim Beautiful As String
Beautiful = "ignorant"
Label1.Text = "The world is full of " & Beautiful & " people."
Why is common sense such an un-common comodity?
|
|
|
|
|
wetrivrrat wrote:
says he loves it
Kudos to you for sticking with your friend through this difficult time....
Your code converters suck, they are still calling old VB6 functions.
The core issue here is that you should not be writing your own cryptography functions, you should use the ones that .NET provides. However, what would help here is for you to show us the C# code you're ending up with and telling us what is going wrong.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I've never used the installed cyrpto....SO if you can help tha'd be auesome!!!
what i'm trying to do is:
Currently i'm passing a string value to a hash table then writing it to isolated storage. the problem is that it saves it in a .bat file which can be moded if opened in notepad THen i'm comparing that .bat file to a hardcoded value in the program (mini license attempt) but the problem is that if someone changes the value in the isolated storage the hash fails(only in debug mode) but since i wrote in string and i'm asking it to compare in string it will eventually pass the test because the string matched. even though the hash didn't. So I need to write to this isolated storage a hash / salt that will not show a string value. ie. i want to store the date of install and compare against the hard coded date in the program (i change that hard code every new install. yes i know thats not the best way, but for this installation it will) this way if someone tries to install it somewhere else it has to pass this and a list of other tests to pass for the install. and so they don't figure out the date is one of the keys i need it in a hash/salt once stored. All my friend was trying to do was give me a quick and dirty method that would do this. if you have an easier way please DO TELL!
Dim Beautiful As String
Beautiful = "ignorant"
Label1.Text = "The world is full of " & Beautiful & " people."
Why is common sense such an un-common comodity?
|
|
|
|
|
You just want to create a hash and compare it to one you've stored ? How about MD5[^] ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote:
How about MD5[^] ?
Again, Never used the crypto, so all i need to do is this:
Hash hash = new Hash ( myAssembly );
Byte[] hashcode = hash.MD5;
myAssembly being the text that i'm trying to save? then would i just need to write hash.MD5 to my iso-storage? ie...
instead of this (Current)
storage["_"] = "Successful Install on " +dt.Date.ToShortDateString();
storage.Save();
this?
Hash hash = new Hash ("Successful Install on " +dt.Date.ToShortDateString())
Byte[] hashcode = hash.MD5
storage["_"] = hash.MD5;
storage.Save();
again, i'm only guessing here, so if not please help me out
Dim Beautiful As String
Beautiful = "ignorant"
Label1.Text = "The world is full of " & Beautiful & " people."
Why is common sense such an un-common comodity?
|
|
|
|
|
Sorry, no. This[^] is the link I meant to give ( clicking on MD5 in the link I gave goes here ).
You need to convert your string to a byte[], then it's:
MD5 md5 = new MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(data);
result is an array of bytes that represents the hash.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote:
You need to convert your string to a byte[], then it's:
Ok, so
byte[] data = new byte[DATA_SIZE];
do i need to set the DATA_SIZE ? or is that automatic?
and then how do i implement this?
it looks like i need to create a new class, then do i define the value of data in the class? or in my storage method?
ONce that is all done, how do i read this data.. aka, how do i reverse this process?
Dim Beautiful As String
Beautiful = "ignorant"
Label1.Text = "The world is full of " & Beautiful & " people."
Why is common sense such an un-common comodity?
|
|
|
|
|
|
I tried that one, it does not work, plus it does not answer the question as it stands now.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
wetrivrrat wrote:
byte[] data = new byte[DATA_SIZE];
do i need to set the DATA_SIZE ? or is that automatic?
*sigh* Look, I have to ask you, when you read this stuff, do you consider what any of it means ? Your array will have a size, and the demo code is showing a variable to give the idea of the syntax. You need to create a byte array the size of the string. Here[^] is an article on converting a string to a byte[] and back.
wetrivrrat wrote:
it looks like i need to create a new class, then do i define the value of data in the class? or in my storage method?
What on earth for ? What makes you think you need to write a class ?
wetrivrrat wrote:
ONce that is all done, how do i read this data.. aka, how do i reverse this process?
Oh - I asked you before if you were comparing a stored hash to a new one. You cannot reverse a hash, that's one thing that makes it secure.
If you want something you can reverse, I'm not sure what algorithm to use. I would recommend retrieving a hash and comparing it to a hash of the value you expect, assuming that's what's going on here. If you're checking for a range, then you need to find another algorithm.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote:
*sigh*
You're not alone! I've been up since 6 somthing this morning going balls to the wall all day. I was sitting in a MS Word 1 intro class when I was writing to you about this(requirement for finacial aid for MCSE, don't ask) So between dealing with a teacher who didn't like me not paying attention, and having the fear of this deadline being bumped up a week I am not thinking too clearly.
that said i greatly appreciate your help thus far... and anything provided beyond this...
I have never had to implement any crypto in my apps, and this being the first i'm struggling to grasp the functions as i was dealing with the teacher...
What I need is the ablility to take today's date, hard code that to the app,
then install my app today, when it loads up the next time it checks to see if the date is the same or not, if it is it does set A of methods, if not it does set B of methods.
I am writing the date of install(installDate) to Isolated Storage thru a hashtable that
stores the info as a string(currently i'm too tired to remember why, and its too big a part of the app to disect it tonight(6hours to delivery) and reconstruct it.) then I compare that string to the date string hard coded in the app as well to today's date.
If a user found the iso-storage and changed the date to todays date then the program would re-install itself. I need to write the installDate to the iso-storage in a non-reconizable format that will then re-construct itself to the date of install for comparison.
I don't care if it is md5 or not, the reason i was looking for a way to convert the vb code was because it did what i needed it to, the problem is that I can't make it work in C#, and i'm not sure what needs to be done at this point to make it work. I tried the app from David Anton, but it has all kinds of errors that I haven't yet had the time/energy to debug, but i'll ask him about those.
If you know of a better way than this please enlighten me.... i'll post the code result from the converter David Anton suggested.
Dim Beautiful As String
Beautiful = "ignorant"
Label1.Text = "The world is full of " & Beautiful & " people."
Why is common sense such an un-common comodity?
|
|
|
|
|