|
What error message are you getting?
Life goes very fast. Tomorrow, today is already yesterday.
modified on Friday, September 25, 2009 5:12 AM
|
|
|
|
|
Strange, your code compiles fine for me.
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)
|
|
|
|
|
Hmmm, maybe his code is exactly as he has put. I mean with the .Add line at class level. That would cause compile error, if I am not mistaken?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Ah, I think I may have it. Is the error:
Invalid token '(' in class, struct, or interface member declaration ?
If so, it's because you can't add to the list outside of a method.
Wrong:
public class MyClass
{
List<CUserMem> MemoryBank = new List<CUserMem>(10);
CUserMem TempCUserMem = new CUserMem();
MemoryBank.Add(TempCUserMem);
} Correct:
public class MyClass
{
List<CUserMem> MemoryBank = new List<CUserMem>(10);
public MyClass()
{
CUserMem TempCUserMem = new CUserMem();
AddToList(TempCUserMem);
}
void AddToList(CUserMem userMem)
{
MemoryBank.Add(userMem);
}
}
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)
|
|
|
|
|
Great Minds...
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Strange, we both reached the same conclusion at exactly the same time!
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)
|
|
|
|
|
You nailed it, Dave.
Thanks for the clear explanation and the code for doing it right. Many people wouldn't have added that. It helps a non c# person making the bigger-than-expected jump from straight c.
Chuck
|
|
|
|
|
No problem - glad to help
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 work with sms and i want to convert my string to binary
this string is
encoded using the 16-bit UCS-2 character encoding
how i can do that;
i try code like comming and it not work
byte[] utf8Bytes = System.Text.Encoding.UTF8.GetBytes(s_unicode);
byte[] utf = System.Text.Encoding.Unicode.GetBytes(s_unicode);
byte[] utf1 = System.Text.Encoding.BigEndianUnicode.GetBytes(s_unicode);
|
|
|
|
|
|
Hi All,
I've been putting together a short program too automatically to find and replace a string within all files of a directory.
For my first set of replacements I want to replace:
• “>” with “>”
• “<” with “<”
Program.CS
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace XMLReformat
{
class Program
{
static void Main(string[] args)
{
string userDir = "C:\\xmlreformat";
try
{
string[] filePaths = Directory.GetFiles(userDir);
foreach (string i in filePaths)
{
Reformat.Replace(i);
}
Console.WriteLine("Operation Succeeded \n \n Press Any Key to Exit");
Console.ReadKey();
}
catch (Exception e)
{
Console.WriteLine("Directory Not Found:" + e.Message);
Console.WriteLine("\n \n Press Any Key to Exit");
Console.ReadKey();
}
}
}
}
Reformat.CS
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace XMLReformat
{
class Reformat
{
public static void Replace(string FName)
{
StreamReader File = new StreamReader(FName);
string fileContent = File.ReadToEnd();
File.Close();
StreamWriter NewFile = new StreamWriter(FName);
string fileContentCopy = fileContent;
string istring1 = ">";
string ostring1 = ">";
string istring2 = "<";
string ostring2 = "<";
fileContentCopy.Replace(istring1, ostring1);
fileContentCopy.Replace(istring2, ostring2);
fileContent = fileContentCopy;
NewFile.Write(fileContent);
}
}
}
However when I run the program it doesnt seem to work at all. Any ideas?
Thanks, George
|
|
|
|
|
GrgBalden wrote: fileContentCopy.Replace(istring1, ostring1);
fileContentCopy.Replace(istring2, ostring2);
String.Replace function returns an altered string, it does not change the instance itself.
You need to use...
fileContentCopy = fileContentCopy.Replace(istring1, ostring1);
fileContentCopy = fileContentCopy.Replace(istring2, ostring2);
I would also like to add that reading a whole file to a string, in my opinion, is not a good thing. I would prefer to read a character at a time and match it to a set of keywords and replace any matches.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hi, Thanks for the help
I've added your suggestion and it seems to be working; I'm now trying to change the file extention of the files in the directory from .txt to .xml
The text files already have the xml, i just need to change the file extention? Any ideas? I tried to impliment an Ext Changer class (last in the list) but doesnt seem to work?
Any provide any sample code?
Program.CS
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace XMLReformat
{
class Program
{
static void Main(string[] args)
{
string userDir = "C:\\xmlreformat";
try
{
string[] filePaths = Directory.GetFiles(userDir);
foreach (string i in filePaths)
{
Reformat.Replace(i);
}
Console.WriteLine("Operation Succeeded \n \n Press Any Key to Exit");
Console.ReadKey();
}
catch (Exception e)
{
Console.WriteLine("Directory Not Found:" + e.Message);
Console.WriteLine("\n \n Press Any Key to Exit");
Console.ReadKey();
}
}
}
}
Reformat.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace XMLReformat
{
class Reformat
{
public static void Replace(string FName)
{
StreamReader File = new StreamReader(FName);
string fileContent = File.ReadToEnd();
File.Close();
StreamWriter NewFile = new StreamWriter(FName);
string fileContentCopy = fileContent;
string istring1 = ">";
string ostring1 = ">";
string istring2 = "<";
string ostring2 = "<";
fileContentCopy = fileContentCopy.Replace(istring1, ostring1);
fileContentCopy = fileContentCopy.Replace(istring2, ostring2);
fileContent = fileContentCopy;
NewFile.Write(fileContent);
NewFile.Close();
}
}
}
ExtChanger.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace XMLReformat
{
class ExtChanger
{
public static void WriteFileName(string userDir, string FName )
{
string NewFN = FName.Replace(".txt", ".XML");
Console.WriteLine(NewFN);
TextWriter tw = new StreamWriter(FName);
}
}
}
|
|
|
|
|
Try using the FileInfo class (in System.IO)...
FileInfo fi = new FileInfo("<FilePath>");
string NewFN = fi.Name.SubString(0, fi.Name.Length - fi.Extension.Length);
NewFN += ".XML";
fi.MoveTo(fi.DirectoryName + NewFN, true);
That should do the trick for you
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
System.Web.HttpUtility.HtmlEncode
and
System.Web.HttpUtility.HtmlDecode
|
|
|
|
|
Thanks for the pointer, I was hoping that someone would know how to change a file extention by changing the file extention using a string?
Any more ideas?
|
|
|
|
|
System.IO.Path.GetFileNameWithoutExtension
and
System.IO.File.Move
|
|
|
|
|
Hello,
I'm trying to make my form blink when it's minimaze or not in focus (like in MSN),
when some event fired.
Is there any option of doing it with C#?
Thanks
modified on Monday, July 27, 2009 12:40 PM
|
|
|
|
|
Have a look at this[^]. Especially the link within to this[^]
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
|
Hi,i can't understand how to get it work only when the window is minimaze,
and a new line or lines added to the kistbox...
Someone can help me here?
|
|
|
|
|
|
No,
He need to fired the TextChaned event (i think).
|
|
|
|
|
If anyone knows or has codegenerator that will create:
public interface IMyInterface
{
IAsyncResult BeginMyMethod(int param,AsyncCallback callback,object state);
int EndMyMethod(IAsyncResult result);
}
from
public interface IMyInterface
{
int MyMethod(int param);
}
I`ve found only java version of it.
|
|
|
|
|