|
bool bExists = new System.IO.FileInfo(@"c:\test.txt").Exists;
long nLength = new System.IO.FileInfo(@"c:\test.txt").Length;
About char*, it's somewhat harder to answer. What's is supposed to be in managed code depends on the semantics of that char* : is it a pointer to a single char (use IntPtr, and marshal to char[] back and forth) ? is it an input string (use String in your method call) ? is it a fixed string (use StringBuilder) ? is it an output string (use ref String) ?
|
|
|
|
|
.S.Rod. wrote:
long nLength = new System.IO.FileInfo(@"c:\test.txt").Length;
This is thing works file.Length;
Is it OK?
.S.Rod. wrote:
About char*, it's somewhat harder to answer.
Wow...
In my case...Usually I do like this C++
Ex: (separator is LPCTSTR )
char* Sep = NULL;<br />
int sepLength = 0;<br />
if (sepLength = strlen (separator)) <br />
{<br />
Sep = new char [sepLength + 1];<br />
strcpy (Sep, separator);<br />
Sep[sepLength] = '\0';<br />
}
Thx Rodrigez for clarfying my newbie doubts.
Don't and drive.
|
|
|
|
|
Kant wrote:
This is thing works file.Length;
fileinfo.Length, to be accurate.
Kant wrote:
In my case...Usually I do like this C++
Ex: (separator is LPCTSTR )
char* Sep = NULL;
int sepLength = 0;
if (sepLength = strlen (separator))
{
Sep = new char [sepLength + 1];
strcpy (Sep, separator);
Sep[sepLength] = '\0';
}
I believe that's what you do with C, not with C++.
At least with C++ you can use the STL std::string, MFC CString, or whatever string class having a copy operator.
In managed code, everything is already done :
String s = separator; //
|
|
|
|
|
|
The file contents are like this:
ABC DFDFAS
- (separator)
DSFS FSDFSDJFSD DSFKDFJS
-
DSFS FSDFSDJFSD DSFKDFJS fsdfsdfasd
I want those strings to be separated by that separator to be stored in array(double linked list) like this:
ABC DFDFAS
DSFS FSDFSDJFSD DSFKDFJS
DSFS FSDFSDJFSD DSFKDFJS fsdfsdfasd
I can write it easily in VC++, but I am getting what I want with C#
string testString;<br />
string[] strArray;<br />
Int64 stringLen;<br />
<br />
stringLen = 0; <br />
<br />
FileStream file = new FileStream(filePath, FileMode.Open, <br />
FileAccess.Read);<br />
<br />
StreamReader sr;<br />
<br />
try<br />
{<br />
sr = new StreamReader(file);<br />
}<br />
catch(Exception ex)<br />
{<br />
return;<br />
}<br />
<br />
do <br />
{<br />
testString = sr.ReadLine() + "\r\n";<br />
strArray = testString.Split('-'); <br />
stringLen = quote.Length;<br />
<br />
for (int i = 0; i < quoteLen; i++) <br />
{<br />
<br />
if (strArray[i] != "")
{ <br />
<br />
if (!wordCounter.Contains(strArray[i])) <br />
{<br />
<br />
wordCounter.Add(strArray[i], 1);<br />
} <br />
else <br />
{<br />
}<br />
}<br />
<br />
}<br />
}<br />
while(sr.Peek() != -1);<br />
<br />
sr.Close();<br />
<br />
file.Close();
All I get is :
ABC
DFDFAS
DSFS
FSDFSDJFSD
....
Can you guide what I am doing wrong..
Don't and drive.
|
|
|
|
|
The problem lies in something that is not defined in this code : what is the class type for wordCounter ?
Is wordCounter a class which implements the IDictionary interface ? In this case, I think the "1" in
wordCounter.Add(strArray[i], 1); is wrong. A unique value is expected.
|
|
|
|
|
.S.Rod. wrote:
what is the class type for wordCounter ?
SortedList wordCounter = new SortedList();
Ignore my code, I started with one thing and ended up doing something else.
If the file contents is like this:
The Code Project Rocks
-
Yes It does.
-
It's Awesome.
I want all those sentences stored in the SortedList.
What's the easiest way?
Don't and drive.
|
|
|
|
|
SortedList sL = new SortedList();
sL.Add( "The Code Project Rocks", 0);
sL.Add( "Yes It does.", 0);
sL.Add( "It's Awesome", 0);
int i=0;
while ( i < sL.Count )
{
MessageBox.Show( sL.GetKey(i).ToString() );
i++;
}
|
|
|
|
|
But before I add those string to SortedList, how to strip to those strings which are separated by the separator ("-") from the file?
Is testString.Split('-') any good?
Don't and drive.
|
|
|
|
|
Kant wrote:
Is testString.Split('-') any good?
Yes. That's the simplest way to do so as long as there are no carriage returns between strings and separators. In which case, I would suggest to concatenate strings as you read the file (use StringBuilder, for performance reasons, since strings are immutable), and then call Split on the full string.
|
|
|
|
|
how to write C# Applet, display it in a web page and the requirement?
Thank in advance for your help.
where ?documentation and tuto
-=zoltx=-
|
|
|
|
|
Basically, it's possible to run a .NET assembly into a IE6-hosted web page by adding these tags :
<object id="myCtl"
classid="http://www.mycode.Microsoft.com/mycode.dll#myClass">
</object>
where mycode.dll is the assembly filename, and myClass is the entry point.
Use http://127.0.0.1/... for local assemblies (you've got to put the assembly in your \wwwroot folder, if you are using IIS).
More info here[^].
|
|
|
|
|
thanks a lot. I want to know if it is possible to pass some parameters ex:
<object id="myCtl" classid="http://www.mycode.Microsoft.com/mycode.dll#myClass" param="2131" param2="qsdf">
|
|
|
|
|
thanks a lot. I want to know if it is possible to pass some parameters ex:
<object id="myCtl" classid="http://www.mycode.Microsoft.com/mycode.dll#myClass" param="2131" param2="qsdf">
-=zoltx=-
|
|
|
|
|
check this link which has sample,
http://www.codeguru.com/forum/showthread.php?s=&threadid=228806&highlight=C+applet
or search Codeguru , forums in C# section only with keyword "C# applets"
-Paresh
|
|
|
|
|
Does anyone has already created a com add-in for mappoint 2002 in C#?
If so, can you provide me some sample code?
I didn't found any usefull C# samples on the net (yet).
Thanks in advance.
|
|
|
|
|
Mappoint 2002 COM add-ins[^] are special COM components that must implement the IDTExtensibility2 interface.
In fact, once your C# code is ready (it must implements the mentioned interface), you just need to use regasm.exe to export it as an unmanaged component. Doing so, it creates a type-library and a progid you can use from MapPoint VisualBasic code.
My guess is that MapPoint 2003 will directly support C# objects.
|
|
|
|
|
|
Hi
I want to use the Keyeven but It dont fonction.
can anyone help me please.
also i used the button caption, but it dont fonction when i do a evenement .
thanks
void textBoxText_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode == Keys.ControlKey)
{
this.textBox.Text = "salut";
);
}
else this.textBox.Text = "salut";
if(e.KeyCode == Keys.Delete) this.textBox.Text = "salut";
this.textBox.Text = "con";
}
|
|
|
|
|
Conditions like e.KeyCode == Keys.ControlKey are valid, and they work. The code snippet you have posted is utter crap (does not even compile), but may be it wasn't on purpose.
|
|
|
|
|
Hi!
I have create my own control in C#. When I try to use it on my WIndows Form I get an HRESULT exception and the control is never created. Anyone knows how can I debbug this in order to detect the error???
Thanks in advance!
|
|
|
|
|
Hello,I'm trying to write a class library which can parse several WebPages automatically by mshml. But I'don't know
how to get a free IHTMLDocument2 interface which is not attatched to any control or view.
Using C++,this can be done by call to CoCreateInstance() function:
MSHTML::IHTMLDocument2Ptr pDoc;
HRESULT hr = CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER,IID_IHTMLDocument2, (void**)&pDoc);
I want to know how to get a free IHTMLDocument2 interface in csharp.
hope I get some replies,
thanks
|
|
|
|
|
It's pretty much unnatural, but here it goes :
using mshtml;
using System.Runtime.InteropServices;
[ ComImport, Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IPersistStreamInit
{
IntPtr GetClassID();
void IsDirty();
void Load(IntPtr pStream);
void Save(IntPtr pStream, bool fClearDirty);
long GetSizeMax();
void InitNew();
}
{
mshtml.HTMLDocumentClass doc = new mshtml.HTMLDocumentClass();
IPersistStreamInit pS = (IPersistStreamInit) doc;
pS.InitNew();
doc.createElement("<a href='http://www.codeproject.com'>link</a>");
MessageBox.Show ("nb elements = " + doc.all.length);
...
}
|
|
|
|
|
|
hi,.S.Rod.
I'm extracting all links from a webpage,after I'use
doc.createElement("link");
how I get all links from page "codeproject".
|
|
|
|