CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

如何实现 VB6 中的 MIDB CHRB ASCB LENB RIGHTB LEFTB 函数?(200分)

楼主changechange(http://access911.net 是我的个人网站,欢迎光临)2006-07-02 21:50:11 在 .NET技术 / C# 提问

以下是   VB6   的代码以及返回值,如何在   C#   VS.NET   2005   中写函数实现下列各个函数的功能?  
   
  Function   test()  
          Debug.Print   AscB("c")  
          Debug.Print   AscB("ccc")  
          Debug.Print   AscB("中国")  
          Debug.Print   LenB("c")  
          Debug.Print   LenB("中国")  
          Debug.Print   AscB(MidB("中",   1,   1))  
          Debug.Print   AscB(MidB("中",   2,   1))  
          Debug.Print   AscB(MidB("c",   1,   1))  
          Debug.Print   AscB(MidB("c",   2,   1))  
          Debug.Print   MidB("c",   2,   1)   =   ""  
          Debug.Print   MidB("c",   1,   1)   =   "c"  
           
  '   上述代码的测试结果如下:  
  '99  
  '99  
  '45  
  '2  
  '4  
  '45  
  '78  
  '99  
  '0  
  'True  
  'False  
   
   
  '如何能实现他们的   C#   .NET   2005   版本?  
             
                 
  End   Function  
   
  以下是我撰写的一些函数,能运行,但是结果都不对  
   
                  public   static   char   Chr(int   CharCode)  
                  {  
                          //方法1  
                          //return   Convert.ToChar(CharCode);  
                           
                          //方法2  
                          //byte[]   bytes   =   new   byte[1];  
                          //bytes[0]   =   (byte)CharCode;  
                          //return   Encoding.GetEncoding("ASCII").GetString(bytes)[0];  
   
                          //方法3  
                          byte[]   bytes   =   new   byte[1];  
                          bytes[0]   =   (byte)CharCode;  
                          return   Encoding.Default.GetString(bytes)[0];  
                   
                   
                  }  
   
   
                  public   static   int   Asc(string   CharWord)  
                  {  
                          //方法1  
                          //return   (int)Encoding.ASCII.GetBytes(CharWord)[0];  
   
                          //方法2  
                          //return   (int)Encoding.GetEncoding("ASCII").GetBytes(CharWord)[0];  
   
                          //方法3  
                          return   (int)Encoding.Default.GetBytes(CharWord)[0];  
                  }  
   
   
                  public   static   int   LenB(string   CharWords)  
                  {  
                          //LenB("c")=1  
                          //return   Encoding.Default.GetBytes(CharWords).Length;  
   
                          //vb6   中   LenB("c")   是2,所以这里也要改为   Unicode  
                          //return   Encoding.Unicode.GetBytes(CharWords).Length;  
   
                          //   第三种方法  
                          return   (int)Encoding.Unicode.GetByteCount(CharWords);  
                  }  
                  public   static   int   AscB(string   CharWord)  
                  {  
                          //int   bytes   =   Encoding.Unicode.GetByteCount(CharWord);             //调试时使用  
                          if   (CharWord   ==   "")  
                          {  
                                  return   0;  
                          }  
                          else  
                          {  
                                  return   (int)Encoding.Unicode.GetBytes(CharWord)[0];  
                          }  
                  }  
                  public   static   string   ChrB(int   CharCode)  
                  {  
                          byte[]   bytes   =   new   byte[1];  
                          bytes[0]   =   (byte)CharCode;  
                          return   Encoding.Default.GetString(bytes)[0].ToString();  
                  }  
   
                  #region MidB  
   
                  public   static   string   MidB(string   CharWords,   int   Start)  
                  {  
                          return   MidB(CharWords,   Start,   0);  
                  }  
   
                  public   static   string   MidB(string   CharWords,   int   Start,   int   ByteSize)  
                  {  
   
                          //byte[]   bytes   =   Encoding.GetEncoding("GB2312").GetBytes(CharWords);  
                          byte[]   bytes   =   Encoding.Unicode.GetBytes(CharWords);  
                          Debug.Print(CharWords   +   "的字节数为:"   +   bytes.GetLength(0).ToString());  
                          if   (ByteSize   ==   0)  
                          {  
                                  return   Encoding.Unicode.GetString(bytes,   Start   -   1,   bytes.Length   -   Start   +   1);  
                          }  
                          else  
                          {  
                                  return   Encoding.Unicode.GetString(bytes,   Start   -   1,   ByteSize);  
                          }  
   
                  }  
   
                  #endregion  
   
   
   
   
   
   
   
   
   
   
   
   
   
  问题点数:100、回复次数:3Top

1 楼wangsaokui(无间道III(终极无间)C#MVP)回复于 2006-07-02 22:24:23 得分 0

you   can   add   the   reference,   right   button   click   references--->add   reference--->Microsoft.VisualBasic  
   
  Then   you   can   use   Substring   methodTop

2 楼wangsaokui(无间道III(终极无间)C#MVP)回复于 2006-07-02 22:29:15 得分 0

using   System;  
  using   Microsoft.VisualBasic;  
  using   System.Text;  
   
  namespace   test  
  {  
  ///   <summary>  
  ///   Summary   description   for   Class1.  
  ///   </summary>  
  public   class   Class1  
  {  
  [STAThread]  
  static   void   Main(string[]   args)  
  {  
                          string   a   =   "abcd";  
                          string   c=   "a";  
                          Console.WriteLine(a.Substring(0,   1));  
   
                          Console.WriteLine(BitConverter.ToString(Encoding.ASCII.GetBytes(c),0));  
                          Console.ReadLine();  
  }  
          }  
  }Top

3 楼Knight94(愚翁)回复于 2006-07-03 09:33:21 得分 100

你所说的RC4算法,我进行了修改,你看看是否可以  
  http://blog.csdn.net/Knight94/archive/2006/07/03/868951.aspxTop

相关问题

关键词

得分解答快速导航

  • 帖主:changechange
  • Knight94

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo