Convert.ToString的问题

qjsbha 2009-08-28 09:10:03
Convert.ToString(charTemp, 16);chartemp是一个特殊字符。这是什么意思?转换后加上%是多少了?
...全文
699 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
liffe 2009-08-28
  • 打赏
  • 举报
回复
angel6709 2009-08-28
  • 打赏
  • 举报
回复
ToString 方法 (Int32, Int32)
.NET Framework 类库
Convert.ToString 方法 (Int32, Int32)
将 32 位有符号整数的值以指定的基数转换为它的等效 String 表示形式。

命名空间:System
程序集:mscorlib(在 mscorlib.dll 中)

语法
Visual Basic(声明)
Public Shared Function ToString ( _
value As Integer, _
toBase As Integer _
) As StringVisual Basic(用法)
Dim value As Integer
Dim toBase As Integer
Dim returnValue As String

returnValue = Convert.ToString(value, toBase)C#
public static string ToString (
int value,
int toBase
)C++
public:
static String^ ToString (
int value,
int toBase
)J#
public static String ToString (
int value,
int toBase
)JScript
public static function ToString (
value : int,
toBase : int
) : String

参数
value
32 位的有符号整数。

toBase
返回值的基数,必须是 2、8、10 或 16。



返回值
以 toBase 为基数的 value 的 String 表示形式。
异常
异常类型 条件
ArgumentException
toBase 不是 2、8、10 或 16。


示例
下面的代码示例使用 ToString 方法,以该方法支持的基数将几个 32 位整数转换为 String。

Visual Basic 复制代码
' Example of the Convert.ToString( Integer, Integer ) method.
Imports System
Imports Microsoft.VisualBasic

Module ConvertRadixIntDemo

Sub RunToStringDemo( )

Dim values as Integer( ) = { _
Integer.MinValue, _
-100, _
0, _
99999, _
Integer.MaxValue }
Dim radices as Integer( ) = { 2, 8, 10, 16 }

' Iterate through the values array.
Dim value as Integer
For Each value in values

' Iterate through the radices.
Dim radix as Integer
For Each radix in radices

' Convert a value with a radix.
Dim valueString As String = _
Convert.ToString( value, radix )

Console.WriteLine( "{0,13} {1,3} {2}", _
value, radix, valueString )
Next radix
Next value
End Sub

Sub Main( )

Console.WriteLine( _
"This example of Convert.ToString( Integer, Integer " & _
") generates " & vbCrLf & "the following output. It " & _
"converts several Integer values to " & vbCrLf & _
"strings using the radixes supported by the method." )
Console.WriteLine( vbCrLf & _
" Value Radix String" & vbCrLf & _
" ----- ----- ------" )

RunToStringDemo( )

End Sub
End Module

' This example of Convert.ToString( Integer, Integer ) generates
' the following output. It converts several Integer values to
' strings using the radixes supported by the method.
'
' Value Radix String
' ----- ----- ------
' -2147483648 2 10000000000000000000000000000000
' -2147483648 8 20000000000
' -2147483648 10 -2147483648
' -2147483648 16 80000000
' -100 2 11111111111111111111111110011100
' -100 8 37777777634
' -100 10 -100
' -100 16 ffffff9c
' 0 2 0
' 0 8 0
' 0 10 0
' 0 16 0
' 99999 2 11000011010011111
' 99999 8 303237
' 99999 10 99999
' 99999 16 1869f
' 2147483647 2 1111111111111111111111111111111
' 2147483647 8 17777777777
' 2147483647 10 2147483647
' 2147483647 16 7fffffffC# 复制代码
// Example of the Convert.ToString( int, int ) method.
using System;

class ConvertRadixIntDemo
{
static void RunToStringDemo( )
{
int[ ] values = {
int.MinValue,
-100,
0,
99999,
int.MaxValue };
int[ ] radices = { 2, 8, 10, 16 };

// Iterate through the values array.
foreach( int value in values )
{
// Iterate through the radices.
foreach( int radix in radices )
{
// Convert a value with a radix.
string valueString =
Convert.ToString( value, radix );

Console.WriteLine( "{0,13} {1,3} {2}",
value, radix, valueString );
}
}
}

static void Main( )
{
Console.WriteLine(
"This example of Convert.ToString( int, int ) " +
"generates \nthe following output. It converts several " +
"int values to \nstrings using the radixes supported " +
"by the method." );
Console.WriteLine(
"\n Value Radix String" +
"\n ----- ----- ------" );

RunToStringDemo( );
}
}

/*
This example of Convert.ToString( int, int ) generates
the following output. It converts several int values to
strings using the radixes supported by the method.

Value Radix String
----- ----- ------
-2147483648 2 10000000000000000000000000000000
-2147483648 8 20000000000
-2147483648 10 -2147483648
-2147483648 16 80000000
-100 2 11111111111111111111111110011100
-100 8 37777777634
-100 10 -100
-100 16 ffffff9c
0 2 0
0 8 0
0 10 0
0 16 0
99999 2 11000011010011111
99999 8 303237
99999 10 99999
99999 16 1869f
2147483647 2 1111111111111111111111111111111
2147483647 8 17777777777
2147483647 10 2147483647
2147483647 16 7fffffff
*/
xzq686 2009-08-28
  • 打赏
  • 举报
回复
转换成16进制的串..
Convert.ToString('a',10) = "97"
上面的是转成10进制

加上 "%"就是"97%"
simen_frankly 2009-08-28
  • 打赏
  • 举报
回复
看不懂啊~能否详细些~~~~~
michaelnami 2009-08-28
  • 打赏
  • 举报
回复
%是转义的意思 d%就是数字
wfcfan 2009-08-28
  • 打赏
  • 举报
回复
变量吧。。?

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧