本文介绍了将字符串以ASCII格式写入数据文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友:
我有一个来自文本框的字符串.我想将此字符串以ASCI格式写入文件.我使用了各种方法,但没有得到任何结果.
例如:
Dear Friend:
I have a string that comes from a textbox. I want to write this string in the format of ASCI to a file. I use various method but i do not get any result.
for example:
private static Encoding encoding = Encoding.ASCII;
private static byte[] CSTB( string cod, Encoding enc )
{
byte[] transformacion = enc.GetBytes( cod );
return transformacion;
}
private void btn_CreateNewCard_Click( object sender , EventArgs e )
{
FileInfo finfo = new FileInfo( path );
using(FileStream fs = finfo .Open( FileMode .Open ,FileAccess .Write , FileShare .ReadWrite ))
try
{
fs .Write( CSTB( "Moha",encoding ),0, CSTB( "Moha",encoding ).Lenght);
}
}
我的代码正确吗?
为什么单击按钮时会看到原始文本("Moha")?
Yours
Is that my code correct?
Why I see the original text ("Moha") when I click my button?
Yours
推荐答案
File.WriteAllText(pathOfFile, "Moha", Encoding.ASCII);
<pre lang="c#">
string EncodedString=BitConverter.ToString(Encoding.ASCII.GetBytes(<ur string>));
这篇关于将字符串以ASCII格式写入数据文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!