java 把char 轉化為int

2021-06-18 14:55:11 字數 580 閱讀 7256

首先說明一下問題由於某個專案的需求需要使用到  int [ ] 的陣列,由於資料最初是 string 型別的,為了方便就先把 string 型別的資料轉化成了 char [ ]  ,可是專案需要的是 int [ ] 的資料,所以還得把 char 轉化成 int  

在轉化的過程中 1,變成了49,2變成了 50....考慮了很久才忽然想起48是 1 的 ascll 值,49 是2 的 ascll值

於是方案就出來了,0到 9 的 ascll 值比 實際值小 48 於是得到如下** 

public class char_to_int

return chartoint;

}public static void main(string args) ;//初始化 char 陣列

for (int i=0;i//輸出char陣列

system.out.println(a[i]+"");

}int b=char_to_int(a);//轉化後的 char 陣列

for (int i=0;i//輸出轉化後的 char 陣列

system.out.println(b[i]);}}

}

把CString轉化為char

正確方法 cstring m head char codefile codefile lpstr lpctstr m head 正確,想辦法去掉字尾 補充 int fnlen m head.getlength strcspn str,codefile new char fnlen 4 codefil...

c 中如何把int轉化成char

在 c 裡把其它 型別轉換 成字串時最好是用純 c 的機制 stringstream 類。include include using namespace std void main stringstream 的 str 方法返回 string string 的 c str 方法則返回 c 字串。應當...

將String轉化為int

package com.utils public class convert 將輸入的字串轉化為int型別 param str 輸入的字串 return 返回該字串對應的int型別 public static int string2int string str long result 0 int i...