当前位置: 技术问答>java相关
如何改String中特定一个位置的字符?
来源: 互联网 发布时间:2017-03-23
本文导语: String s="00000"; 我要将s的第一个字符改为"1",如何做? | new char[] chArray=s.toCharArray(); chArray[0]='1'; s=new String(chArray); | CString::SetAt void SetAt( int nIndex, TCHAR ch ); Parameters nIndex ...
String s="00000";
我要将s的第一个字符改为"1",如何做?
我要将s的第一个字符改为"1",如何做?
|
new char[] chArray=s.toCharArray();
chArray[0]='1';
s=new String(chArray);
chArray[0]='1';
s=new String(chArray);
|
CString::SetAt
void SetAt( int nIndex, TCHAR ch );
Parameters
nIndex
Zero-based index of the character in the CString object. The nIndex parameter must be greater than or equal to 0 and less than the value returned by GetLength. The Debug version of the Microsoft Foundation Class Library will validate the bounds of nIndex; the Release version will not.
ch
The character to insert.
Remarks
You can think of a CString object as an array of characters. The SetAt member function overwrites a single character specified by an index number. SetAt will not enlarge the string if the index exceeds the bounds of the existing string.
CString Overview | Class Members | Hierarchy Chart
See Also CString::GetAt, CString::operator [ ]
--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
////CSDN January 2001////
void SetAt( int nIndex, TCHAR ch );
Parameters
nIndex
Zero-based index of the character in the CString object. The nIndex parameter must be greater than or equal to 0 and less than the value returned by GetLength. The Debug version of the Microsoft Foundation Class Library will validate the bounds of nIndex; the Release version will not.
ch
The character to insert.
Remarks
You can think of a CString object as an array of characters. The SetAt member function overwrites a single character specified by an index number. SetAt will not enlarge the string if the index exceeds the bounds of the existing string.
CString Overview | Class Members | Hierarchy Chart
See Also CString::GetAt, CString::operator [ ]
--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
////CSDN January 2001////