日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

如鹏网.Net基础2 专题课:ASCII码和拆数

發布時間:2025/4/9 asp.net 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如鹏网.Net基础2 专题课:ASCII码和拆数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

第 1 節 ASCII介紹和char轉換為int

美國標準信息交換碼

計算機中存儲的都是二進制數據。

什么是ASCII碼?

char和int的轉換;

char的大寫小轉換;

‘1’轉換為1;和1轉換為‘1’

0 ?空字符

8 退格(Backspace)

9 Tab

13 回車

32 空格

48 ?0-9?

65 A-Z

97 a-z

char[0,65535]

//把char轉換為int(可隱式轉換)

char和int各種轉換namespace ConsoleApplication7 {class Program{static void Main(string[] args){/*Console.WriteLine(int.MaxValue);Console.WriteLine(int.MinValue);Console.WriteLine((int)char.MaxValue);//65535,顯式轉換,以便于匹配WriteLine的int類型的重載Console.WriteLine((int)char.MinValue);//0char c='a';Console.WriteLine(c);int i = c;//把char隱式轉換為int(int范圍比char大)//只要把char數據隱式或者顯式轉換為int,得到的int就是char的ASCII碼Console.WriteLine(i);*//*char c = (char)97;Console.WriteLine(c);int i = 98;char c1 = (char)i;Console.WriteLine(c1);*//*//'1'和1的區別char c1 = '1';//49int i1 = 1;//1int i2 = c1;Console.WriteLine(i2);Console.WriteLine(c1==i1);*//*char c1 = '0';char c2 = (char)(c1 + 2);//不能(char)c1+1Console.WriteLine(c2);char c3 = '5';char c4 = (char)(c3-2);Console.WriteLine(c4);*///Console.WriteLine(intToChar(5));//Console.WriteLine(charToInt('3'));Console.WriteLine(toUpper('d'));Console.ReadKey();}/// <summary>/// 把1轉換為'1',2轉換為'2'/// </summary>/// <param name="i"></param>/// <returns></returns> static char intToChar(int i) { if (i < 0 || i > 9) { throw new Exception("i必須在0-9之間"); } return (char)('0' + i);//i=3 } /// <summary> /// 把'1'轉換為1 /// </summary> /// <param name="c"></param> /// <returns></returns> static int charToInt(char c) { //'0','1'....'9' if (c < '0' || c > '9')//判斷是否是數字字符 { throw new Exception("不是合法的數字字符"); } return c - '0'; } //'a'→'A' static char toUpper(char c) { if (c < 'a' || c > 'z') { throw new Exception("不是小寫字符"); } //'a':97,'A':65;'c':99,'C':67 //研究發現小寫字符比大寫字符大32 //return c //return (char)(c - 32); return (char)(c-('a'-'A')); } //任務:寫一個轉換為小寫的方法 } }

?

------------------------------------------------
第 2 節 char的加減法

------------------------------------------------
第 3 節 各種轉換

------------------------------------------------
第 4 節 取得一個數各個位的值

class Program{static void Main(string[] args){/*int i = 365;//就是三位數int sheng = 365;int ge = sheng % 10;// int ge = i % 10;Console.WriteLine("個位"+ge);//int sheng = i / 10;//36sheng = sheng / 10;Console.WriteLine("剩" + sheng);int shi = sheng % 10;Console.WriteLine("十位" + shi);sheng = sheng / 10;Console.WriteLine("剩" + sheng);int bai = sheng % 10;Console.WriteLine("百位"+bai);sheng = sheng / 10;Console.WriteLine("剩" + sheng);*//*int n = 3721886;int sheng = n;while (sheng != 0){int wei = sheng % 10;Console.WriteLine(wei);sheng = sheng / 10;}*/int n = 3721886;string s = n.ToString();//項目中哪個方便用哪個。面試的時候盡量不用.net內置的方法for (int i = 0; i < s.Length; i++){char ch = s[i];int iWei = ch-'0';//'1'→1//Console.WriteLine(ch);Console.WriteLine(iWei); } Console.ReadKey(); } }

?

------------------------------------------------
第 5 節 自測題

1)?將給定的金額轉換為中文,比如輸入1235,則返回"壹貳叁伍"。

2)?數字加千分位:要求用戶輸入一個整數,編寫一個方法,方法將整數轉換為一個從低位開始每三位一個逗號的“千分位”字符串表示形式。比如用戶輸入1123556,則返回”1,123,556”

3)?輸出1-999中能被3整除,而且至少有一位數字是5的所有數字,比如165、555、525。

4)?編寫一個方法,返回某個字符在某個字符串中出現的次數。"abchahah"中'a'出現了3次。int GetCharCount(string s,char c)返回字符串s中c出現的次數。

?

如鵬網:http://www.rupeng.com

轉載于:https://www.cnblogs.com/wjs5943283/p/5239236.html

總結

以上是生活随笔為你收集整理的如鹏网.Net基础2 专题课:ASCII码和拆数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。