|
You forgot to say "pretty please?".
I'm going to sulk, now.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
help me please
|
|
|
|
|
Sure. Show me what you've done yourself, and point out which bits aren't functioning as you expect, and I'll help you fix them.
I'm not however going to do all the work for you.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
I have tried in this mode:
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Configuration;
class Server
{
public static void Main()
{
char EOF = (char)0x00;
try
{
IPAddress ipAd = IPAddress.Parse("127.0.0.1");
TcpListener myList = new TcpListener(ipAd, 2055);
myList.Start();
Console.WriteLine("The server is running. Waiting for a connection....");
Socket soc = myList.AcceptSocket();
Stream s = new NetworkStream(soc);
StreamReader sr = new StreamReader(s);
StreamWriter sw = new StreamWriter(s);
sw.WriteLine("Benvenuti sul server! digita EXIT per disconnetterti." + EOF);
sw.Flush();
bool quit = false;
while (!quit)
{
string msg = sr.ReadLine();
if (msg == null) quit = true;
if (msg != "EXIT")
{
sw.WriteLine("Guest: <b>" + msg + "</b>" + EOF);
sw.Flush();
}
else
{
quit = true;
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
|
|
|
|
|
That compiles with no errors or warnings. So, what's the problem?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Why do you need to convert it? Just make it a method and use it, C#.NET allows you to mix languages.
|
|
|
|
|
Hi
I have to search for a string in a binary file using BinaryReader. How can I do this?
I have searched on Google and MSDN but got nothing.
Thanks in advance.
|
|
|
|
|
By opening the file using the BinaryReader [^], and reading from it. You can use the ReadString [^] method to do so. Then compare the data that you read to the data that you're searching.
SimpleData wrote: I have searched on Google and MSDN but got nothing.
In what language did you query Google?
I'm sure there won't be a ready-to-go solution indeed, but you can put the different parts together to form a new solution
"please help in this regard. give the visual basic code for this as soon possible."
|
|
|
|
|
I've searched in English.
I tried doing it with ReadString but as I have said it didn't work.
Here is the code I was using:
FileStream fs = new FileStream("name.exe",FileMode.Open,FileAccess.ReadWrite);
BinaryReader br = new BinaryReader(fs);
string buff = String.Empty;
while(buff != "blablabla")
{
buff = br.ReadString();
if(buff == "blablabla")
Console.WriteLine("Found!");
}
I wrote this string to the end of file with BinaryWriter with this code.
FileStream fs = new FileStream("name.exe",FileMode.Open,FileAccess.ReadWrite);
BinaryWriter bw = new BinaryWriter(bw);
bw.Seek(0,SeekOrigin.End);
bw.Write("blablabla");
When I open the file with an hex editor I can see that my string is there but I can't find it with these codes.
modified on Saturday, July 11, 2009 2:55 PM
|
|
|
|
|
Try something like this;
FileStream fs = new FileStream("C:\\Windows\\System32\\calc.exe", FileMode.Open, FileAccess.ReadWrite);
BinaryReader br = new BinaryReader(fs);
string searchTerm = "manifestVersion";
byte[] file = new byte[fs.Length];
fs.Read(file, 0, (int)fs.Length);
string asText = Encoding.UTF8.GetString(file);
int index = asText.IndexOf(searchTerm);
Console.WriteLine("Found @position: " + index);
Console.WriteLine("'" + asText.Substring(index, searchTerm.Length) + "'");
Console.ReadKey();
"please help in this regard. give the visual basic code for this as soon possible."
modified on Saturday, July 11, 2009 5:23 PM
|
|
|
|
|
Hi,
I don't agree. Your code assumes all the file data is text; if it is, why use a BinaryReader at all? if it isn't, you need to interpret the binary data to locate the parts that are supposed to be strings, then treat those with code similar to yours, making sure to obey the string conventions in the file (length+content, content+NULL, whatever).
And if you don't know the file format, or just want to find everything that might be a string, then you must check for ASCII or Unicode characters explicitly, you can't just feed arbitrry binary data to an Encoder.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Luc Pattyn wrote: you must check for ASCII or Unicode characters explicitly
Run through the byte array, checking whether the byte is between 0 and 127, and if it is, convert it using Encoding.ASCII?
In retrospect, wouldn't it be faster to convert the searchterm and look in the array of bytes for that sequence?
"Do I give you even the slightest impression that I fear anything? Chuck Norris works for me." - JSOP[ ^]
|
|
|
|
|
Yes, if you know the string you want to find, converting it to bytes and then search bytes would be fastest. One would need to do this at least twice to accommodate for both ASCII and Unicode.
OTOH getting "all" the strings from a file works best the other way around: check a sequence of bytes for appropriate values (e.g. between 32 and 127, possibly alternating with zeros) and some mimimum length; doing it this way will miss all special characters, say the accented e, Euro/Pound sign, etc.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Ok, so it is obvious what the problem is.
Lets look at what you have:
1) an EXE file (binary, random data as far as BinaryReader is concerned).
2) add "blablabla" to the end.
3) a loop that does not end unless it suceeds in finding your string, or runs out of stream and throws an exception, that you aren't catching.
4) an equality test that is failing.
If I rewrote this as:
string s = @"hello there! This is what you are looking for: blablabla";
if(s == "blablabla")
{
Console.Writeline("Give the man a million bucks");
}
else
{
Console.WriteLine("Give the man a dead fish");
}
Do you think you could spot the problem yourself?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
ReadString reads some kind of crappy length-prefixed string.. which means it can decide to read sometime like 2GB of data if you're lucky (nice EndOfStream exception).
I'd search for the first character, then see if the next character from the stream is the second character that you are searching, you can find the way from here.
|
|
|
|
|
Hi i want to have time in arraylist like following
9:45 AM
10:00 AM
10:15 AM
10:30 AM
....
so basically 15 mins are added to previous item..
How to do this?
Pls reply ASAP.
|
|
|
|
|
Member 3981366 wrote: Pls reply ASAP.
This is more likely to stop people from replying. Everybody here is a volunteer, if your problem is that urgent, then get your credit card out and go to rentacoder.com.
Firstly, try not to use ArrayList , use List<T> instead. It is type safe and more efficient. Look it up in the documentation for further details.
Something like:
List<DateTime> timeList = new List<DateTime>();
DateTime startTime = new DateTime(1, 1, 1, 9, 0, 0);
DateTime endTime = new DateTime(1, 1, 1, 18, 0, 0);
while (startTime <= endTime)
{
timeList.Add(startTime);
startTime.AddMinutes(15);
}
would work.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
To me, "ASAP" means the same as "when you can get around to it".
|
|
|
|
|
What will you do with it?
Depending on what you plan to do, you may not actually need to store all that in memory.
Here's an enumerator from my TimeRanger[^] article:
public static System.Collections.Generic.IEnumerable<System.DateTime>
MinuteEnumerator
(
System.DateTime StartPoint
,
System.DateTime EndPoint
,
ushort SteppingFactor
)
{
System.DateTime current = PIEBALD.Lib.LibTim.DateTruncate
(
StartPoint
,
PIEBALD.Lib.LibTim.TimeGranularity.Minute
) ;
if ( StartPoint <= EndPoint )
{
if ( current < StartPoint )
{
current = current.AddMinutes ( 1 ) ;
}
while ( current <= EndPoint )
{
yield return ( current ) ;
current = current.AddMinutes ( SteppingFactor ) ;
}
}
else
{
while ( current >= EndPoint )
{
yield return ( current ) ;
current = current.AddMinutes ( SteppingFactor*-1 ) ;
}
}
yield break ;
}
Or you could use this to load a List if you really want to store the information.
|
|
|
|
|
how to use ascii code??
i want when i press enter key my button is click.
how i do this???
|
|
|
|
|
Firstly, read the bit at the top of this list, where is says "How to get an answer to your question".
"Hi.." is not a description of your problem. A description that relates to the problem encourages people who think "I might know the answer to that" to look, and maybe, to answer...
Secondly, I know English is not your first language, so I am guessing that what you want is:
You have a form of some kind (lets call it Form1), which has a button (lets call it Button1).
When you press the Enter key, you want the buttons click event to be fired.
If so, then: Click on Form1 in the design view, and look at the properties.
Find the "Accept Button" property.
Use the drop down list to select "Button1"
Build your project.
Enter will now activate the Button1 Click event.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Jeepers. Have you thought about buying a book ? Have you read my article on how to use google ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
If I can't use Google, how am I supposed to find your article...?
|
|
|
|
|
If they have the ability to use a forum to post these messages, they shouldn't have any problems using Google.
|
|
|
|
|
Hi there,
I have a StreamEvent from a StockExchange Data Provider API. The Event is triggered every time a new price occurs for the respective Instrument on the Exchange.
I can fill the Stream with multiple Intruments, lets say 50.000. So the StreamEvent is triggered about mutiple thousand times in one second.
In the Stream, I first check the price difference in percent between the last price and the new one:
private double abw;
void TPBrief_Brief(int SymbolNr, float NewPrice, float Volume, DateTime Time)
{
abw = (((InstrumentObject)os[SymbolNr]).LastPrice - NewPrice) / (((InstrumentObject)os[SymbolNr]).LastPrice/ 100);
if (abw >= 1.5) {
}
As you can see, I hold my Instrument Objects in a Hashtable, key is Symbolnr, value the InstrumentObject. The first line in this event is the one which is triggered that often, so I just want to know how to optimize this line.
As I learned from various articles, Hashtable should be replaced with a Dictionary, this is one thing I will do.
But what about this variation:
void TPBrief_Brief(int SymbolNr, float NewPrice, float Volume, DateTime Time)
{
IntrumentObject io = ((InstrumentObject)os[SymbolNr]);
abw = (io.LastPrice - NewPrice) / (io.LastPrice/ 100);
if (abw >= 1.5) {
}
Could this be faster than the first one? What's about the Calculation of the difference? Can this code fragment be optimized?
Any help would be appreciated!
|
|
|
|
|