|
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.
|
|
|
|
|
|
I am want to create a simple windows application,it's some options for i want to add.
If u run the application, At the time Task Manager,Esc,windows keys are disabled.how to do?
|
|
|
|
|
Member 4235601 wrote: If u run the application, At the time Task Manager,Esc,windows keys are disabled.how to do?
Why would anybody do that?
The only application which would like do this is some kind of malware.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
When your application running, create one separate thread which will continiously checking for process "Taskmgr.exe", if found then kill the process .
Why are you trying to do this ?
|
|
|
|
|
You could have your application shut the computer down. Only downside with that is none of the keys will do anything after that
Of course, that's not a serious solution, but it's about as serious as I see your requirements. What valid reason would you have to disable the functions you have asked for?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
In your registry at
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\
System
set DisableTaskMgr value to 1
first you have to create a key in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\
named: "System" with a subkey(REG_DWORD) named "DisableTaskMgr" with value set to 1
|
|
|
|