Index: Include/Classes/ActiveBasic/Strings/Strings.ab
===================================================================
--- Include/Classes/ActiveBasic/Strings/Strings.ab	(revision 272)
+++ Include/Classes/ActiveBasic/Strings/Strings.ab	(revision 272)
@@ -0,0 +1,217 @@
+'Classes/ActiveBasic/Strings/Strings.ab
+
+#ifndef __ACTIVEBASIC_STRINGS_STRINGS_AB__
+#define __ACTIVEBASIC_STRINGS_STRINGS_AB__
+
+#require <Classes/System/Math.ab>
+#require <Classes/System/Collections/ArrayList.ab>
+
+Namespace ActiveBasic
+Namespace Strings
+
+Sub ChrFill(p As PWSTR, n As SIZE_T, c As WCHAR)
+	Dim i As SIZE_T
+	For i = 0 To ELM(n)
+		p[i] = c
+	Next
+End Sub
+
+Sub ChrFill(p As PSTR, n As SIZE_T, c As SByte)
+	Dim i As SIZE_T
+	For i = 0 To ELM(n)
+		p[i] = c
+	Next
+End Sub
+
+Function ChrCopy(dst As PCWSTR, src As PCWSTR, size As SIZE_T) As PCWSTR
+	memcpy(dst, src, size * SizeOf (WCHAR))
+	Return dst
+End Function
+
+Function ChrCopy(dst As PCSTR, src As PCSTR, size As SIZE_T) As PCSTR
+	memcpy(dst, src, size)
+	Return dst
+End Function
+
+Function ChrMove(dst As PCWSTR, src As PCWSTR, size As SIZE_T) As PCWSTR
+	MoveMemory(dst, src, size * SizeOf (WCHAR))
+	Return dst
+End Function
+
+Function ChrMove(dst As PCSTR, src As PCSTR, size As SIZE_T) As PCSTR
+	MoveMemory(dst, src, size)
+	Return dst
+End Function
+
+Function StrCmp(s1 As PCWSTR, s2 As PCWSTR) As Long
+	Dim i = 0 As SIZE_T
+	While s1[i] = s2[i]
+		If s1[i] = 0 Then
+			Exit While
+		End If
+		i++
+	Wend
+	Return s1[i] As Long - s2[i]
+End Function
+
+Function StrCmp(s1 As PCSTR, s2 As PCSTR) As Long
+	Dim i = 0 As SIZE_T
+	While s1[i] = s2[i]
+		If s1[i] = 0 Then
+			Exit While
+		End If
+		i++
+	Wend
+	Return s1[i] As Long - s2[i]
+End Function
+
+
+
+Function ChrCmp(s1 As PCWSTR, s2 As PCWSTR, size As SIZE_T) As Long
+	Dim i = 0 As SIZE_T
+	While i <> size 'Forではsize = 0のときにまずい
+		ChrCmp = s1[i] As Long - s2[i]
+		If ChrCmp <> 0 Then
+			Exit Function
+		End If
+		i++
+	Wend
+End Function
+
+Function ChrCmp(s1 As PCSTR, s2 As PCSTR, size As SIZE_T) As Long
+	Dim i = 0 As SIZE_T
+	While i <> size
+		ChrCmp = s1[i] As Long - s2[i]
+		If ChrCmp <> 0 Then
+			Exit Function
+		End If
+		i++
+	Wend
+End Function
+
+Function ChrCmp(s1 As PCWSTR, size1 As SIZE_T, s2 As PCWSTR, size2 As SIZE_T) As Long
+	ChrCmp = ChrCmp(s1, s2, System.Math.Min(size1, size2))
+	If ChrCmp = 0 Then
+		ChrCmp = size1 - size2
+	End If
+End Function
+
+Function ChrCmp(s1 As PCSTR, size1 As SIZE_T, s2 As PCSTR, size2 As SIZE_T) As Long
+	ChrCmp = ChrCmp(s1, s2, System.Math.Min(size1, size2))
+	If ChrCmp = 0 Then
+		ChrCmp = size1 - size2
+	End If
+End Function
+
+Function ChrPBrk(str As PCWSTR, cStr As SIZE_T, chars As PCWSTR, cChars As SIZE_T) As SIZE_T
+	Dim i As SIZE_T
+	For i = 0 To ELM(cStr)
+		If ChrFind(chars, cChars, str[i]) <> -1 Then
+			Return i
+		End If
+	Next
+	Return -1 As SIZE_T
+End Function
+
+Function ChrPBrk(str As PCSTR, cStr As SIZE_T, Chars As PCSTR, cChars As SIZE_T) As SIZE_T
+	Dim i As SIZE_T
+	For i = 0 To ELM(cStr)
+		If ChrFind(Chars, cChars, str[i]) <> -1 Then
+			Return i
+		End If
+	Next
+	Return -1 As SIZE_T
+End Function
+
+Function ChrFind(s As PCWSTR, size As SIZE_T, c As WCHAR) As SIZE_T
+	Dim i As SIZE_T
+	For i = 0 To ELM(size)
+		If s[i] = c Then
+			Return i
+		End If
+	Next
+	Return -1 As SIZE_T
+End Function
+
+Function ChrFind(s As PCSTR, size As SIZE_T, c As CHAR) As SIZE_T
+	Dim i As SIZE_T
+	For i = 0 To ELM(size)
+		If s[i] = c Then
+			Return i
+		End If
+	Next
+	Return -1 As SIZE_T
+End Function
+
+Function ChrFind(s1 As PCWSTR, len1 As SIZE_T, s2 As PCWSTR, len2 As SIZE_T) As SIZE_T
+	If len2 = 0 Then
+		'ChrFind = 0
+		Exit Function
+	End If
+	Do
+		Dim prev = ChrFind
+		ChrFind = ChrFind(VarPtr(s1[prev]), (len1 - prev) As SIZE_T, s2[0])
+		If ChrFind = -1 As SIZE_T Then
+			Exit Function
+		End If
+		ChrFind += prev
+
+		If ChrCmp(VarPtr(s1[ChrFind]), s2, len2) = 0 Then
+			Exit Function
+		End If
+		ChrFind++
+		If ChrFind = len1 Then
+			ChrFind = -1
+			Exit Function
+		End If
+	Loop
+End Function
+
+Function ChrFind(s1 As PCSTR, len1 As SIZE_T, s2 As PCSTR, len2 As SIZE_T) As SIZE_T
+	If len2 = 0 Then
+		'ChrFind = 0
+		Exit Function
+	End If
+	Do
+		Dim prev = ChrFind
+		ChrFind = ChrFind(VarPtr(s1[prev]), (len1 - prev) As SIZE_T, s2[0])
+		If ChrFind = -1 As SIZE_T Then
+			Exit Function
+		End If
+		ChrFind += prev
+
+		If ChrCmp(VarPtr(s1[ChrFind]), s2, len2) = 0 Then
+			Exit Function
+		End If
+		ChrFind++
+		If ChrFind = len1 Then
+			ChrFind = -1
+			Exit Function
+		End If
+	Loop
+End Function
+
+Namespace Detail
+Function Split(s As String, c As StrChar) As /*System.*/ArrayList '暫定
+	Split = New /*System.*/ArrayList
+
+	Dim last = 0 As Long
+	Do
+		Dim i = s.IndexOf(c, last)
+		If i < 0 Then
+			Split.Add(s.Substring(last, s.Length - last))
+			Exit Function
+		End If
+		Split.Add(s.Substring(last, i - last))
+		last = i + 1
+		If last > s.Length Then
+			Split.Add(System.String.Empty)
+		End If
+	Loop
+End Function
+End Namespace 'Detail
+
+End Namespace 'Strings
+End Namespace 'ActiveBasic
+
+#endif '__ACTIVEBASIC_STRINGS_STRINGS_AB__
Index: Include/Classes/ActiveBasic/Strings/index.ab
===================================================================
--- Include/Classes/ActiveBasic/Strings/index.ab	(revision 272)
+++ Include/Classes/ActiveBasic/Strings/index.ab	(revision 272)
@@ -0,0 +1,3 @@
+'Classes/ActiveBasic/Strings/index.ab
+
+#require <Classes/ActiveBasic/Strings/Strings.ab>
Index: Include/Classes/System/DateTime.ab
===================================================================
--- Include/Classes/System/DateTime.ab	(revision 271)
+++ Include/Classes/System/DateTime.ab	(revision 272)
@@ -178,5 +178,5 @@
 	End Function
 
-	Static Function ToDay() As DateTime
+	Static Function Today() As DateTime
 		Dim time As SYSTEMTIME
 		GetLocalTime(time)
@@ -292,10 +292,11 @@
 		Dim dateFormatSize = GetDateFormat(LOCALE_USER_DEFAULT, 0, time, NULL, NULL, 0)
 		Dim timeFormatSize = GetTimeFormat(LOCALE_USER_DEFAULT, 0, time, NULL, NULL, 0)
-		Dim dateTimeFormats = malloc(dateFormatSize + timeFormatSize) As PTSTR
+		Dim strLength = dateFormatSize + timeFormatSize
+		Dim dateTimeFormats = GC_malloc_atomic(SizeOf (TCHAR) * (strLength)) As PTSTR
 		GetDateFormat(LOCALE_USER_DEFAULT, 0, time, NULL, dateTimeFormats, dateFormatSize)
 		dateTimeFormats[dateFormatSize - 1] = Asc(" ")
 		GetTimeFormat(LOCALE_USER_DEFAULT, 0, time, NULL, dateTimeFormats + dateFormatSize, timeFormatSize)
-
-		Return New String(dateTimeFormats)
+'Debug
+		Return New String(dateTimeFormats, strLength)
 	End Function
 
Index: Include/Classes/System/String.ab
===================================================================
--- Include/Classes/System/String.ab	(revision 271)
+++ Include/Classes/System/String.ab	(revision 272)
@@ -2,4 +2,6 @@
 
 #require <basic/function.sbp>
+#require <Classes/System/Text/StringBuilder.ab>
+#require <Classes/ActiveBasic/Strings/Strings.ab>
 
 #ifdef __STRING_IS_NOT_ALWAYS_UNICODE
@@ -21,47 +23,75 @@
 
 		m_Length As Long
+		Chars As *StrChar
+
+		Sub validPointerCheck(p As VoidPtr, size = 1 As Long)
+			If p As ULONG_PTR < &h10000 Then
+				'Throw ArgumentException
+				Debug
+			ElseIf IsBadReadPtr(p, size As ULONG_PTR) Then
+				'Throw ArgumentException
+				Debug
+			End If
+		End Sub
 	Public
-		Chars As *StrChar
+		Static Const Empty = New String
 
 		Sub String()
-			Chars = _System_malloc(SizeOf (StrChar))
-			Chars[0] = 0
-			m_Length = 0
+'			Chars = 0
+'			m_Length = 0
+		End Sub
+
+		Sub String(initStr As PCWSTR)
+			validPointerCheck(initStr)
+			Assign(initStr, lstrlenW(initStr))
+		End Sub
+
+		Sub String(initStr As PCWSTR, length As Long)
+			validPointerCheck(initStr, length)
+			Assign(initStr, length)
+		End Sub
+
+		Sub String(initStr As PCWSTR, start As Long, length As Long)
+			If start < 0 Or length Or start + length < 0 Then
+				'Throw New ArgumentOutOfRangeException
+			End If
+			validPointerCheck(initStr + start, length)
+			Assign(initStr + start, length)
 		End Sub
 
 		Sub String(initStr As PCSTR)
-			Assign(initStr)
+			validPointerCheck(initStr)
+			Assign(initStr, lstrlenA(initStr))
 		End Sub
 
 		Sub String(initStr As PCSTR, length As Long)
+			validPointerCheck(initStr, length)
 			Assign(initStr, length)
 		End Sub
 
-		Sub String(initStr As PCWSTR)
-			Assign(initStr)
-		End Sub
-
-		Sub String(initStr As PCWSTR, length As Long)
-			Assign(initStr, length)
-		End Sub
-
-		Sub String(ByRef initStr As String)
-			Assign(initStr)
-		End Sub
-
-		Sub String(length As Long)
-			ReSize(length)
+		Sub String(initStr As PCSTR, start As Long, length As Long)
+			If start < 0 Or length Or start + length < 0 Then
+				'Throw New ArgumentOutOfRangeException
+			End If
+			validPointerCheck(initStr + start, length)
+			Assign(initStr + start, length)
+		End Sub
+		
+		Sub String(initStr As String)
+			If Not String.IsNullOrEmpty(initStr) Then
+				Assign(initStr.Chars, initStr.m_Length)
+			End If
 		End Sub
 
 		Sub String(initChar As StrChar, length As Long)
-			ReSize(length, initChar)
-		End Sub
-
-		Sub ~String()
-			_System_free(Chars)
-			Chars = 0
-#ifdef _DEBUG
-			m_Length = 0
-#endif
+			AllocStringBuffer(length)
+			ActiveBasic.Strings.ChrFill(Chars, length, initChar)
+			Chars[length] = 0
+		End Sub
+
+		Sub String(sb As System.Text.StringBuilder)
+			Chars = StrPtr(sb)
+			m_Length = sb.Length
+			sb.__Stringized()
 		End Sub
 
@@ -75,100 +105,80 @@
 
 		Const Function Operator [] (n As Long) As StrChar
-#ifdef _DEBUG
-			If n > Length Then
-				'Throw ArgumentOutOfRangeException
-				Debug
-			End If
-#endif
+			rangeCheck(n)
 			Return Chars[n]
 		End Function
 
-		Sub Operator []= (n As Long, c As StrChar)
-#ifdef _DEBUG
-			If n >= Length Then
-				'Throw ArgumentOutOfRangeException
-				Debug
-			End If
-#endif
-			Chars[n] = c
-		End Sub
-
-	/*	Const Function Operator + (text As *Byte) As String
-			Return Concat(text As PCTSTR, lstrlen(text))
-		End Function*/
-
-		Const Function Operator + (text As PCSTR) As String
-			Return Concat(text, lstrlenA(text))
-		End Function
-
-		Const Function Operator + (text As PCWSTR) As String
-			Return Concat(text, lstrlenW(text))
-		End Function
-
-		Const Function Operator + (objString As String) As String
-			Return Concat(objString.Chars, objString.m_Length)
-		End Function
-
-		Const Function Operator & (text As PCSTR) As String
-			Dim tempString = This + text
+		Const Function Operator + (y As PCSTR) As String
+			Return Concat(y, lstrlenA(y))
+		End Function
+
+		Const Function Operator + (y As PCWSTR) As String
+			Return Concat(y, lstrlenW(y))
+		End Function
+
+		Const Function Operator + (y As String) As String
+			Return Concat(y.Chars, y.m_Length)
+		End Function
+
+		Const Function Operator & (y As PCSTR) As String
+			Return This + y
+		End Function
+
+		Const Function Operator & (y As PCWSTR) As String
+			Dim tempString = This + y
 			Return tempString
 		End Function
 
-		Const Function Operator & (text As PCWSTR) As String
-			Dim tempString = This + text
+		Const Function Operator & (y As String) As String
+			Dim tempString = This + y
 			Return tempString
 		End Function
 
-		Const Function Operator & (objString As String) As String
-			Dim tempString = This + objString
-			Return tempString
-		End Function
-
-		Const Function Operator == (objString As String) As Boolean
-			Return String.Compare(This, objString) = 0
-		End Function
-
-		Const Function Operator == (text As *StrChar) As Boolean
-			Return _System_StrCmp(This.Chars, text) = 0
-		End Function
-
-		Const Function Operator <> (objString As String) As Boolean
-			Return String.Compare(This, objString) <> 0
-		End Function
-
-		Const Function Operator <> (text As *StrChar) As Boolean
-			Return _System_StrCmp(This.Chars, text) <> 0
-		End Function
-
-		Const Function Operator < (objString As String) As Boolean
-			Return String.Compare(This, objString) < 0
-		End Function
-
-		Const Function Operator < (text As *StrChar) As Boolean
-			Return _System_StrCmp(This.Chars, text) < 0
-		End Function
-
-		Const Function Operator > (objString As String) As Boolean
-			Return String.Compare(This, objString) > 0
-		End Function
-
-		Const Function Operator > (text As *StrChar) As Boolean
-			Return _System_StrCmp(This.Chars, text) > 0
-		End Function
-
-		Const Function Operator <= (objString As String) As Boolean
-			Return String.Compare(This, objString) <= 0
-		End Function
-
-		Const Function Operator <= (text As *StrChar) As Boolean
-			Return _System_StrCmp(This.Chars, text) <= 0
-		End Function
-
-		Const Function Operator >= (objString As String) As Boolean
-			Return String.Compare(This, objString) >= 0
-		End Function
-
-		Const Function Operator >= (text As *StrChar) As Boolean
-			Return _System_StrCmp(This.Chars, text) >= 0
+		Const Function Operator == (y As String) As Boolean
+			Return String.Compare(This, y) = 0
+		End Function
+
+		Const Function Operator == (y As *StrChar) As Boolean
+			Return String.Compare(This, y) = 0
+		End Function
+
+		Const Function Operator <> (y As String) As Boolean
+			Return String.Compare(This, y) <> 0
+		End Function
+
+		Const Function Operator <> (y As *StrChar) As Boolean
+			Return String.Compare(This, y) <> 0
+		End Function
+
+		Const Function Operator < (y As String) As Boolean
+			Return String.Compare(This, y) < 0
+		End Function
+
+		Const Function Operator < (y As *StrChar) As Boolean
+			Return String.Compare(This, y) < 0
+		End Function
+
+		Const Function Operator > (y As String) As Boolean
+			Return String.Compare(This, y) > 0
+		End Function
+
+		Const Function Operator > (y As *StrChar) As Boolean
+			Return String.Compare(This, y) > 0
+		End Function
+
+		Const Function Operator <= (y As String) As Boolean
+			Return String.Compare(This, y) <= 0
+		End Function
+
+		Const Function Operator <= (y As *StrChar) As Boolean
+			Return String.Compare(This, y) <= 0
+		End Function
+
+		Const Function Operator >= (y As String) As Boolean
+			Return String.Compare(This, y) >= 0
+		End Function
+
+		Const Function Operator >= (y As *StrChar) As Boolean
+			Return String.Compare(This, y) >= 0
 		End Function
 
@@ -177,25 +187,51 @@
 		End Function
 
+	Public
 		Static Function Compare(x As String, indexX As Long, y As String, indexY As Long, length As Long) As Long
-			Return CompareOrdinal(x, indexX, y, indexY, length)
+			Return String.CompareOrdinal(x, indexX, y, indexY, length)
 		End Function
 
 		Static Function CompareOrdinal(x As String, y As String) As Long
-			Return _System_StrCmp(x.Chars, y.Chars)
+			Return String.CompareOrdinal(x.Chars, y.Chars)
 		End Function
 
 		Static Function CompareOrdinal(x As String, indexX As Long, y As String, indexY As Long, length As Long) As Long
-			If Object.ReferenceEquals(x, Nothing) Then
-				If Object.ReferenceEquals(y, Nothing) Then
+			Return String.CompareOrdinal(x.Chars, indexX, y.Chars, indexY, length)
+		End Function
+	Private
+		Static Function Compare(x As String, y As *StrChar) As Long
+			Return String.CompareOrdinal(x, y)
+		End Function
+
+		Static Function CompareOrdinal(x As String, y As *StrChar) As Long
+			Return String.CompareOrdinal(x.Chars, y)
+		End Function
+
+		Static Function CompareOrdinal(x As *StrChar, y As *StrChar) As Long
+			If x = 0 Then
+				If y = 0 Then
 					Return 0
 				Else
 					Return -1
 				End If
-			ElseIf Object.ReferenceEquals(y, Nothing) Then
+			ElseIf y = 0 Then
 				Return 1
 			End If
-			Return _System_StrCmpN(VarPtr(x.Chars[indexX]), VarPtr(y.Chars[indexY]), length As SIZE_T)
-		End Function
-
+			Return ActiveBasic.Strings.StrCmp(x, y)
+		End Function
+
+		Static Function CompareOrdinal(x As *StrChar, indexX As Long, y As *StrChar, indexY As Long, length As Long) As Long
+			If x = 0 Then
+				If y = 0 Then
+					Return 0
+				Else
+					Return -1
+				End If
+			ElseIf y = 0 Then
+				Return 1
+			End If
+			Return ActiveBasic.Strings.ChrCmp(VarPtr(x[indexX]), VarPtr(y[indexY]), length As SIZE_T)
+		End Function
+	Public
 		Function CompareTo(y As String) As Long
 			Return String.Compare(This, y)
@@ -207,5 +243,5 @@
 	'			Throw New ArgumentException
 	'		End If
-			Return CompareTo(y)
+			Return CompareTo(y As String)
 		End Function
 
@@ -213,27 +249,5 @@
 			Return Chars
 		End Function
-
-		Sub ReSize(allocLength As Long)
-			If allocLength < 0 Then Exit Sub
-			Dim oldLength  = m_Length
-			If AllocStringBuffer(allocLength) <> 0 Then
-				If allocLength > oldLength Then
-					ZeroMemory(VarPtr(Chars[oldLength]), SizeOf (StrChar) * (m_Length - oldLength + 1))
-				Else
-					Chars[m_Length] = 0
-				End If
-			End If
-		End Sub
-
-		Sub ReSize(allocLength As Long, c As StrChar)
-			If allocLength < 0 Then Exit Sub
-			Dim oldLength = m_Length
-			If AllocStringBuffer(allocLength) <> 0 Then
-				If allocLength > oldLength Then
-					_System_FillChar(VarPtr(Chars[oldLength]), (m_Length - oldLength) As SIZE_T, c)
-				End If
-				Chars[m_Length] = 0
-			End If
-		End Sub
+Private
 
 		Sub Assign(text As PCSTR, textLengthA As Long)
@@ -261,50 +275,4 @@
 		End Sub
 
-		Sub Assign(ByRef objString As String)
-			Assign(objString.Chars, objString.m_Length)
-		End Sub
-
-		Sub Assign(text As PCSTR)
-			If text Then
-				Assign(text, lstrlenA(text))
-			Else
-				If Chars <> 0 Then
-					Chars[0] = 0
-				End If
-				m_Length = 0
-			End If
-		End Sub
-
-		Sub Assign(text As PCWSTR)
-			If text Then
-				Assign(text, lstrlenW(text))
-			Else
-				If Chars <> 0 Then
-					Chars[0] = 0
-				End If
-				m_Length = 0
-			End If
-		End Sub
-
-		Sub Append(text As *StrChar, textLength As Long)
-			Dim prevLen As Long
-			prevLen = m_Length
-			If AllocStringBuffer(m_Length + textLength) <> 0 Then
-				memcpy(VarPtr(Chars[prevLen]), text, SizeOf (StrChar) * textLength)
-				Chars[m_Length] = 0
-			End If
-		End Sub
-
-		Sub Append(text As *StrChar)
-			Append(text, lstrlen(text))
-		End Sub
-
-		Sub Append(ByRef str As String)
-			Append(str.Chars, str.m_Length)
-		End Sub
-
-		Const Function Clone() As String
-			Return This
-		End Function
 	Private
 		Static Function ConcatStrChar(text1 As *StrChar, text1Length As Long, text2 As *StrChar, text2Length As Long) As String
@@ -312,6 +280,6 @@
 			With ConcatStrChar
 				.AllocStringBuffer(text1Length + text2Length)
-				memcpy(.Chars, text1, SizeOf (StrChar) * text1Length)
-				memcpy(VarPtr(.Chars[text1Length]), text2, SizeOf (StrChar) * text2Length)
+				ActiveBasic.Strings.ChrCopy(.Chars, text1, text1Length As SIZE_T)
+				ActiveBasic.Strings.ChrCopy(VarPtr(.Chars[text1Length]), text2, text2Length As SIZE_T)
 				.Chars[text1Length + text2Length] = 0
 			End With
@@ -324,6 +292,7 @@
 			With Concat
 				Dim lenW = MultiByteToWideChar(CP_THREAD_ACP, 0, text, len, 0, 0)
+				Concat = New String
 				.AllocStringBuffer(m_Length + lenW)
-				memcpy(.Chars, This.Chars, m_Length)
+				ActiveBasic.Strings.ChrCopy(.Chars, This.Chars, m_Length)
 				MultiByteToWideChar(CP_THREAD_ACP, 0, text, len, VarPtr(.Chars[m_Length]), lenW)
 				.Chars[m_Length + lenW] = 0
@@ -335,7 +304,8 @@
 #ifdef __STRING_IS_NOT_UNICODE
 			With Concat
+				Concat = New String
 				Dim lenA = WideCharToMultiByte(CP_THREAD_ACP, 0, text, len, 0, 0, 0, 0)
 				.AllocStringBuffer(m_Length + lenA)
-				memcpy(.Chars, This.Chars, m_Length)
+				ActiveBasic.Strings.ChrCopy(.Chars, This.Chars, m_Length As SIZE_T)
 				WideCharToMultiByte(CP_THREAD_ACP, 0, text, len, VarPtr(.Chars[m_Length]), lenA, 0, 0)
 				.Chars[m_Length + lenA] = 0
@@ -358,27 +328,48 @@
 		End Function
 
-		Const Function Contains(objString As String) As Boolean
-			Return IndexOf(objString, 0, m_Length) >= 0
-		End Function
-
-		Const Function Contains(lpszText As *StrChar) As Boolean
-			Return IndexOf(lpszText, 0, m_Length) >= 0
-		End Function
-
-		Const Function IndexOf(lpszText As *StrChar) As Long
-			Return IndexOf(lpszText, 0, m_Length)
-		End Function
-
-		Const Function IndexOf(lpszText As *StrChar, startIndex As Long) As Long
-			Return IndexOf(lpszText, startIndex, m_Length - startIndex)
-		End Function
-
-		Const Function IndexOf(lpszText As *StrChar, startIndex As Long, count As Long) As Long
-			Dim length = lstrlen(lpszText)
-
-			If startIndex < 0 Then Return -1
-			If count < 1 Or count + startIndex > m_Length Then Return -1
-			If length > m_Length Then Return -1
-
+		Const Function Contains(s As String) As Boolean
+			If Object.ReferenceEquals(s, Nothing) Then
+				'Throw New ArgumentNullException
+			End If
+			Return IndexOf(s, 0, m_Length) >= 0
+		End Function
+
+		Const Function IndexOf(c As StrChar) As Long
+			Return indexOfCore(c, 0, m_Length)
+		End Function
+
+		Const Function IndexOf(c As StrChar, start As Long) As Long
+			rangeCheck(start)
+			Return indexOfCore(c, start, m_Length - start)
+		End Function
+
+		Const Function IndexOf(c As StrChar, start As Long, count As Long) As Long
+			rangeCheck(start, count)
+			Return indexOfCore(c, start, count)
+		End Function
+	Private
+		Const Function indexOfCore(c As StrChar, start As Long, count As Long) As Long
+			indexOfCore = ActiveBasic.Strings.ChrFind(VarPtr(Chars[start]), count, c)
+			If indexOfCore <> -1 Then
+				indexOfCore += start
+			End If
+		End Function
+	Public
+		Const Function IndexOf(s As String) As Long
+			Return IndexOf(s, 0, m_Length)
+		End Function
+
+		Const Function IndexOf(s As String, startIndex As Long) As Long
+			Return IndexOf(s, startIndex, m_Length - startIndex)
+		End Function
+
+		Const Function IndexOf(s As String, startIndex As Long, count As Long) As Long
+			rangeCheck(startIndex, count)
+			If Object.ReferenceEquals(s, Nothing) Then
+				'Throw New ArgumentNullException
+				Debug
+			End If
+
+			Dim length = s.Length
 			If length = 0 Then Return startIndex
 
@@ -386,5 +377,5 @@
 			For i = startIndex To startIndex + count - 1
 				For j = 0 To length - 1
-					If Chars[i + j] = lpszText[j] Then
+					If Chars[i + j] = s[j] Then
 						If j = length - 1 Then Return i
 					Else
@@ -396,19 +387,25 @@
 		End Function
 
-		Const Function LastIndexOf(lpszText As *StrChar) As Long
-			Return LastIndexOf(lpszText, m_Length - 1, m_Length)
-		End Function
-
-		Const Function LastIndexOf(lpszText As *StrChar, startIndex As Long) As Long
-			Return LastIndexOf(lpszText As *StrChar, startIndex, startIndex + 1)
-		End Function
-
-		Const Function LastIndexOf(lpszText As *StrChar, startIndex As Long, count As Long) As Long
-			Dim length = lstrlen(lpszText)
-
-			If startIndex < 0 Or startIndex > m_Length - 1 Then Return -1
-			If count < 1 Or count > startIndex + 2 Then Return -1
+		Const Function LastIndexOf(s As String) As Long
+			Return LastIndexOf(s, m_Length - 1, m_Length)
+		End Function
+
+		Const Function LastIndexOf(s As String, startIndex As Long) As Long
+			Return LastIndexOf(s, startIndex, startIndex + 1)
+		End Function
+
+		Const Function LastIndexOf(s As String, startIndex As Long, count As Long) As Long
+			If Object.ReferenceEquals(s, Nothing) Then
+				'Throw New ArgumentNullException
+				Debug
+			End If
+
+			If startIndex < 0 Or startIndex > m_Length - 1 Or _
+				count < 0 Or count > startIndex + 2 Then
+				'Throw New ArgumentOutOfRangeException
+				Debug
+			End If
+			Dim length = s.Length
 			If length > m_Length Then Return -1
-
 			If length = 0 Then Return startIndex
 
@@ -416,5 +413,5 @@
 			For i = startIndex To  startIndex - count + 1 Step -1
 				For j = length - 1 To 0 Step -1
-					If Chars[i + j] = lpszText[j] Then
+					If Chars[i + j] = s[j] Then
 						If j = 0 Then Return i
 					Else
@@ -426,63 +423,37 @@
 		End Function
 
-		Const Function StartsWith(lpszText As *StrChar) As Boolean
-			Return IndexOf(lpszText) = 0
-		End Function
-
-		Const Function EndsWith(lpszText As *StrChar) As Boolean
-			Return LastIndexOf(lpszText) = m_Length - lstrlen(lpszText)
+		Const Function StartsWith(s As String) As Boolean
+			Return IndexOf(s) = 0
+		End Function
+
+		Const Function EndsWith(s As String) As Boolean
+			Return LastIndexOf(s) = m_Length - s.Length
 		End Function
 
 		Const Function Insert(startIndex As Long, text As String) As String
-			Return Insert(startIndex, text.Chars, text.Length)
-		End Function
-
-		Const Function Insert(startIndex As Long, text As *StrChar) As String
-			Return Insert(startIndex, text, lstrlen(text))
-		End Function
-
-		Const Function Insert(startIndex As Long, text As *StrChar, length As Long) As String
-			If startIndex < 0 Or startIndex > m_Length Or length < 0 Then
-				Debug 'ArgumentOutOfRangeException
-
-			End If
-			Insert = New String(m_Length + length)
-			memcpy(Insert.Chars, Chars, SizeOf (StrChar) * startIndex)
-			memcpy(VarPtr(Insert.Chars[startIndex]), text, SizeOf (StrChar) * length)
-			memcpy(VarPtr(Insert.Chars[startIndex + length]), VarPtr(Chars[startIndex]), SizeOf (StrChar) * (m_Length - startIndex + 1))
-		End Function
-
-		Const Function SubString(startIndex As Long) As String
-			Return SubString(startIndex, m_Length - startIndex)
-		End Function
-
-		Const Function SubString(startIndex As Long, length As Long) As String
-			If startIndex < 0 Or length <= 0 Then Return ""
-			If startIndex + length > m_Length Then Return ""
-
-			Dim temp As String
-			temp.AllocStringBuffer(length)
-			memcpy(temp.Chars, VarPtr(Chars[startIndex]), SizeOf (StrChar) * length)
-			temp.Chars[length] = 0
-			Return temp
+			Dim sb = New System.Text.StringBuilder(This)
+			sb.Insert(startIndex, text)
+			Return sb.ToString
+		End Function
+
+		Const Function Substring(startIndex As Long) As String
+			rangeCheck(startIndex)
+			Return Substring(startIndex, m_Length - startIndex)
+		End Function
+
+		Const Function Substring(startIndex As Long, length As Long) As String
+			rangeCheck(startIndex, length)
+			Return New String(Chars, startIndex, length)
 		End Function
 
 		Const Function Remove(startIndex As Long) As String
-			If startIndex < 0 Or startIndex > m_Length Then
-				Debug 'ArgumentOutOfRangeException
-			End If
-
-			Remove = New String(startIndex)
-			memcpy(Remove.Chars, This.Chars, SizeOf (StrChar) * startIndex)
+			rangeCheck(startIndex)
+			Remove = Substring(0, startIndex)
 		End Function
 
 		Const Function Remove(startIndex As Long, count As Long) As String
-			If startIndex < 0 Or count < 0 Or startIndex + count > m_Length Then
-				Debug 'ArgumentOutOfRangeException
-			End If
-
-			Remove = New String(m_Length - count)
-			memcpy(Remove.Chars, This.Chars, SizeOf (StrChar) * startIndex)
-			memcpy(VarPtr(Remove.Chars[startIndex]), VarPtr(This.Chars[startIndex + count]), SizeOf (StrChar) * (m_Length - startIndex - count))
+			Dim sb = New System.Text.StringBuilder(This)
+			sb.Remove(startIndex, count)
+			Remove = sb.ToString
 		End Function
 
@@ -497,75 +468,49 @@
 
 		Const Function Replace(oldChar As StrChar, newChar As StrChar) As String
-			Replace = Copy(This)
-			With Replace
-				Dim i As Long
-				For i = 0 To ELM(.m_Length)
-					If .Chars[i] = oldChar Then
-						.Chars[i] = newChar
-					End If
-				Next
-			End With
-		End Function
-
-		Const Function Replace(ByRef oldStr As String, ByRef newStr As String) As String
-	'		If oldStr = Nothing Then Throw ArgumentNullException
-	'
-	'		If newStr = Nothing Then
-	'			Return ReplaceCore(oldStr, oldStr.m_Length, "", 0)
-	'		Else
-				Return ReplaceCore(oldStr, oldStr.m_Length, newStr, newStr.m_Length)
-	'		End If
-		End Function
-
-		Const Function Replace(oldStr As *StrChar, newStr As *StrChar) As String
-			If oldStr = 0 Then Debug 'Throw ArgumentNullException
-			If newStr = 0 Then newStr = ""
-			Return ReplaceCore(oldStr, lstrlen(oldStr), newStr, lstrlen(newStr)) 
-		End Function
-
-		Const Function Replace(oldStr As *StrChar, oldLen As Long, newStr As *StrChar, newLen As Long) As String
-			If oldStr = 0 Then Debug 'Throw ArgumentNullException
-			If newStr = 0 Then
-				newStr = ""
-				newLen = 0
-			End If
-			Return ReplaceCore(oldStr, oldLen, newStr, newLen)
+			Dim sb = New System.Text.StringBuilder(This)
+			sb.Replace(oldChar, newChar)
+			Replace = sb.ToString
+		End Function
+
+		Const Function Replace(oldStr As String, newStr As String) As String
+			Dim sb = New System.Text.StringBuilder(This)
+			sb.Replace(oldStr, newStr)
+			Return sb.ToString
 		End Function
 
 		Const Function ToLower() As String
-			ToLower.ReSize(m_Length)
+			Dim sb = New System.Text.StringBuilder(m_Length)
+			sb.Length = m_Length
 			Dim i As Long
 			For i = 0 To ELM(m_Length)
-				ToLower.Chars[i] = _System_ASCII_ToLower(Chars[i])
+				sb[i] = _System_ASCII_ToLower(Chars[i])
 			Next
+			Return sb.ToString
 		End Function
 
 		Const Function ToUpper() As String
-			ToUpper.ReSize(m_Length)
+			Dim sb = New System.Text.StringBuilder(m_Length)
+			sb.Length = m_Length
 			Dim i As Long
 			For i = 0 To ELM(m_Length)
-				ToUpper.Chars[i] = _System_ASCII_ToUpper(Chars[i])
+				sb[i] = _System_ASCII_ToUpper(Chars[i])
 			Next
-		End Function
-	/*
-		Sub Swap(ByRef x As String)
-			Dim tempLen As Long
-			Dim tempChars As *StrChar
-			tempLen = x.m_Length
-			tempChars = x.Chars
-			x.m_Length = This.m_Length
-			x.Chars = This.Chars
-			This.m_Length = tempLen
-			This.Chars = tempChars
-		End Sub
-	*/
+			Return sb.ToString
+		End Function
+
 		Override Function ToString() As String
-			Return This
-		End Function
-
+			ToString = This
+		End Function
+
+		Const Function Clone() As String
+			Clone = This
+		End Function
 		Static Function Copy(s As String) As String
-			Copy.ReSize(s.m_Length)
-			memcpy(Copy.Chars, This.Chars, SizeOf (StrChar) * m_Length)
-		End Function
+			Copy = New String(s.Chars, s.m_Length)
+		End Function
+
+		Sub CopyTo(sourceIndex As Long, destination As *StrChar, destinationIndex As Long, count As Long)
+			ActiveBasic.Strings.ChrCopy(VarPtr(destination[destinationIndex]), VarPtr(Chars[sourceIndex]), count As SIZE_T)
+		End Sub
 
 		Override Function GetHashCode() As Long
@@ -577,47 +522,66 @@
 			Return _System_GetHashFromWordArray(Chars As *Word, size)
 		End Function
+
+		Function PadLeft(total As Long) As String
+			PadLeft(total, &h30 As StrChar)
+		End Function
+
+		Function PadLeft(total As Long, c As StrChar) As String
+			If total < 0 Then
+				'Throw New ArgumentException
+			End If
+			If total >= m_Length Then
+				Return This
+			End If
+			Dim sb = New System.Text.StringBuilder(total)
+			sb.Append(c, total - m_Length)
+			sb.Append(This)
+			Return sb.ToString
+		End Function
+
+		Function PadRight(total As Long) As String
+			PadLeft(total, &h30 As StrChar)
+		End Function
+
+		Function PadRight(total As Long, c As StrChar) As String
+			If total < 0 Then
+				'Throw New ArgumentException
+			End If
+			If total >= m_Length Then
+				Return This
+			End If
+			Dim sb = New System.Text.StringBuilder(total)
+			sb.Append(This)
+			sb.Append(c, total - m_Length)
+			Return sb.ToString
+		End Function
 	Private
-		' メモリ確保に失敗すると元の文字列は失われない。（例外安全でいう強い保障）
 		Function AllocStringBuffer(textLength As Long) As *StrChar
 			If textLength < 0 Then
 				Return 0
-			ElseIf textLength > m_Length or Chars = 0 Then
-				AllocStringBuffer = _System_realloc(Chars, SizeOf(StrChar) * (textLength + 1))
-				If AllocStringBuffer <> 0 Then
-					m_Length = textLength
-					Chars = AllocStringBuffer
-				End If
-			Else
-				m_Length = textLength
-				AllocStringBuffer = Chars
-			End If
-		End Function
-
-		Function ReplaceCore(oldStr As *StrChar, oldLen As Long, newStr As *StrChar, newLen As Long) As String
-			If oldLen = 0 Then
-				Debug 'Throw ArgumentException
-			End If
-			Dim tmp As String
-			With tmp
-				Dim current = 0 As Long
-				Do
-					Dim pos = IndexOf(oldStr, current)
-					If pos = -1 Then
-						Exit Do
-					End If
-					.Append(VarPtr(Chars[current]), pos - current)
-					.Append(newStr, newLen)
-					current = pos + oldLen
-				Loop
-				.Append(VarPtr(Chars[current]), m_Length - current)
-			End With
-			Return tmp
+			End If
+			AllocStringBuffer = GC_malloc_atomic(SizeOf(StrChar) * (textLength + 1))
+			If AllocStringBuffer = 0 Then
+				'Throw New OutOfMemoryException
+			End If
+			m_Length = textLength
+			Chars = AllocStringBuffer
 		End Function
 
 		Sub AssignFromStrChar(text As *StrChar, textLength As Long)
-			If text = Chars Then Exit Sub
-			If AllocStringBuffer(textLength) <> 0 Then
-				memcpy(Chars, text, SizeOf (StrChar) * textLength)
-				Chars[m_Length] = 0
+			AllocStringBuffer(textLength)
+			ActiveBasic.Strings.ChrCopy(Chars, text, textLength As SIZE_T)
+			Chars[m_Length] = 0
+		End Sub
+
+		Const Sub rangeCheck(index As Long)
+			If index < 0 Or index > m_Length Then
+				Debug 'ArgumentOutOfRangeException
+			End If
+		End Sub
+		
+		Const Sub rangeCheck(start As Long, length As Long)
+			If start < 0 Or start > This.m_Length Or length < 0 Then
+				Debug 'ArgumentOutOfRangeException
 			End If
 		End Sub
Index: Include/Classes/System/Text/StringBuilder.ab
===================================================================
--- Include/Classes/System/Text/StringBuilder.ab	(revision 272)
+++ Include/Classes/System/Text/StringBuilder.ab	(revision 272)
@@ -0,0 +1,564 @@
+'Classes/System/Text/StringBuilder.ab
+
+#require <Classes/ActiveBasic/Strings/Strings.ab>
+
+Namespace System
+Namespace Text
+
+Class StringBuilder
+	'Inherits ISerializable
+Public
+	Sub StringBuilder()
+		initialize(1024)
+	End Sub
+
+	Sub StringBuilder(capacity As Long)
+		initialize(capacity)
+	End Sub
+
+	Sub StringBuilder(s As String)
+		initialize(s, 0, s.Length, s.Length * 2)
+	End Sub
+
+	Sub StringBuilder(capacity As Long, maxCapacity As Long)
+		initialize(capacity, maxCapacity)
+	End Sub
+
+	Sub StringBuilder(s As String, capacity As Long)
+		initialize(s, 0, s.Length, capacity)
+	End Sub
+
+	Sub StringBuilder(s As String, startIndex As Long, length As Long, capacity As Long)
+		initialize(s, startIndex, length, capacity)
+	End Sub
+
+	'Methods
+
+	Function Append(x As Boolean) As StringBuilder
+		Append(Str$(x))
+		Return This
+	End Function
+
+	Function Append(x As StrChar) As StringBuilder
+		EnsureCapacity(size + 1)
+		separateBuffer()
+		chars[size] = x
+		size++
+		Return This
+	End Function
+
+#ifdef __STRING_IS_NOT_UNICODE
+	Function Append(x As Word) As StringBuilder
+		Append(Str$(x As DWord))
+		Return This
+	End Function
+#else
+	Function Append(x As SByte) As StringBuilder
+		Append(Str$(x As Long))
+		Return This
+	End Function
+#endif
+	
+	Function Append(x As Byte) As StringBuilder
+		Append(Str$(x As DWord))
+		Return This
+	End Function
+
+	Function Append(x As Integer) As StringBuilder
+		Append(Str$(x As Long))
+		Return This
+	End Function
+
+	Function Append(x As Long) As StringBuilder
+		Append(Str$(x))
+		Return This
+	End Function
+
+	Function Append(x As DWord) As StringBuilder
+		Append(Str$(x))
+		Return This
+	End Function
+
+	Function Append(x As Int64) As StringBuilder
+		Append(Str$(x))
+		Return This
+	End Function
+
+	Function Append(x As QWord) As StringBuilder
+		Append(Str$(x))
+		Return This
+	End Function
+
+	Function Append(x As Single) As StringBuilder
+		Append(Str$(x))
+		Return This
+	End Function
+
+	Function Append(x As Double) As StringBuilder
+		Append(Str$(x))
+		Return This
+	End Function
+
+	Function Append(x As Object) As StringBuilder
+		Append(x.ToString)
+		Return This
+	End Function
+
+	Function Append(c As StrChar, n As Long) As StringBuilder
+		EnsureCapacity(size + n)
+		ActiveBasic.Strings.ChrFill(VarPtr(chars[size]), n As SIZE_T, c)
+		size += n
+		Return This
+	End Function
+
+	Function Append(s As String) As StringBuilder
+		If Not String.IsNullOrEmpty(s) Then
+			appendCore(s, 0, s.Length)
+		End If
+		Return This
+	End Function
+
+	Function Append(s As String, startIndex As Long, count As Long) As StringBuilder
+		If s = 0 Then
+			If startIndex = 0 And count = 0 Then
+				Return This
+			Else
+				'Throw ArgumentNullException
+			End If
+		End If
+		StringBuilder.rangeCheck2(s.Length, startIndex, count)
+		appendCore(s, startIndex, count)
+		Return This
+	End Function
+
+	Function Append(s As *StrChar, startIndex As Long, count As Long) As StringBuilder
+		If s = 0 Then
+			If startIndex = 0 And count = 0 Then
+				Return This
+			Else
+				'Throw ArgumentNullException
+			End If
+		ElseIf startIndex < 0 Or count < 0 Then
+			'Throw ArgumentOutOfRangeException
+		End If
+		appendCore(s, startIndex, count)
+		Return This
+	End Function
+Private
+	Sub appendCore(s As *StrChar, start As Long, count As Long)
+		EnsureCapacity(size + count)
+		separateBuffer()
+		ActiveBasic.Strings.ChrCopy(VarPtr(chars[size]), VarPtr(s[start]), count As SIZE_T)
+		size += count
+	End Sub
+
+	Sub appendCore(s As String, start As Long, count As Long)
+		EnsureCapacity(size + count)
+		separateBuffer()
+		s.CopyTo(start, chars, size, count)
+		size += count
+	End Sub
+Public
+	'AppendFormat
+
+	Function AppendLine() As StringBuilder
+		separateBuffer()
+		Append(Environment.NewLine)
+		Return This
+	End Function
+
+	Function AppendLine(s As String) As StringBuilder
+		EnsureCapacity(Capacity + s.Length + Environment.NewLine.Length)
+		separateBuffer()
+		Append(s)
+		Append(Environment.NewLine)
+		Return This
+	End Function
+
+	Const Sub CopyTo(sourceIndex As Long, ByRef dest[] As StrChar, destIndex As Long, count As Long)
+		If dest = 0 Then
+			'Throw ArgumentNullException
+		ElseIf size < sourceIndex + count Or sourceIndex < 0 Or destIndex < 0 Or count < 0 Then
+			'Throw ArgumentOutOfRangeException
+		End If
+
+		memcpy(VarPtr(dest[destIndex]), VarPtr(chars[sourceIndex]), count * SizeOf (StrChar))
+	End Sub
+
+	Function EnsureCapacity(c As Long) As Long
+		If c < 0 Or c > MaxCapacity Then
+			'Throw ArgumentOutOfRangeException
+		ElseIf c > Capacity Then
+			Dim p = GC_malloc_atomic((c + 1) * SizeOf (StrChar)) As *StrChar
+			If p = 0 Then
+				'Throw OutOfMemoryException
+				Debug
+			End If
+			ActiveBasic.Strings.ChrCopy(p, chars, size As SIZE_T)
+			chars = p
+			capacity = c
+			stringized = False
+		End If
+	End Function
+
+	'Override Function Equals(o As Object) As Boolean
+
+	Const Function Equals(s As StringBuilder) As Boolean
+		Return ActiveBasic.Strings.StrCmp(chars, s.chars) = 0 _
+			And capacity = s.capacity _
+			And maxCapacity = s.maxCapacity
+	End Function
+
+	Override Function GetHashCode() As Long
+#ifdef __STRING_IS_NOT_UNICODE
+		Dim n = (size + 1) >> 1
+#else
+		Dim n = size
+#endif
+		Return _System_GetHashFromWordArray(chars As *Word, n As SIZE_T) Xor capacity Xor maxCapacity
+	End Function
+
+	Function Insert(i As Long, x As Boolean) As StringBuilder
+		rangeCheck(i)
+		insertCore(i, Str$(x))
+		Return This
+	End Function
+
+	Function Insert(i As Long, x As StrChar) As StringBuilder
+		Insert(i, VarPtr(x), 0, 1)
+		Return This
+	End Function
+#ifdef __STRING_IS_NOT_UNICODE
+	Function Insert(i As Long, x As Word) As StringBuilder
+		rangeCheck(i)
+		insertCore(i, Str$(x As DWord))
+		Return This
+	End Function
+#else
+	Function Insert(i As Long, x As SByte) As StringBuilder
+		rangeCheck(i)
+		insertCore(i, Str$(x As Long))
+		Return This
+	End Function
+#endif
+
+	Function Insert(i As Long, x As Byte) As StringBuilder
+		rangeCheck(i)
+		insertCore(i, Str$(x))
+		Return This
+	End Function
+
+	Function Insert(i As Long, x As Integer) As StringBuilder
+		rangeCheck(i)
+		insertCore(i, Str$(x))
+		Return This
+	End Function
+
+	Function Insert(i As Long, x As Long) As StringBuilder
+		rangeCheck(i)
+		insertCore(i, Str$(x))
+		Return This
+	End Function
+
+	Function Insert(i As Long, x As DWord) As StringBuilder
+		rangeCheck(i)
+		insertCore(i, Str$(x))
+		Return This
+	End Function
+
+	Function Insert(i As Long, x As Int64) As StringBuilder
+		rangeCheck(i)
+		insertCore(i, Str$(x))
+		Return This
+	End Function
+
+	Function Insert(i As Long, x As Single) As StringBuilder
+		rangeCheck(i)
+		insertCore(i, Str$(x))
+		Return This
+	End Function
+
+	Function Insert(i As Long, x As Double) As StringBuilder
+		rangeCheck(i)
+		insertCore(i, Str$(x))
+		Return This
+	End Function
+
+	Function Insert(i As Long, s As String) As StringBuilder
+		rangeCheck(i)
+		insertCore(i, s)
+		Return This
+	End Function
+
+	Function Insert(i As Long, o As Object) As StringBuilder
+		rangeCheck(i)
+		insertCore(i, o.ToString)
+		Return This
+	End Function
+
+	Function Insert(index As Long, x As String, n As Long) As StringBuilder
+		rangeCheck(index)
+		If n < 0 Then
+			'Throw New ArgumentOutOfRangeException
+			Debug
+		End If
+		Dim len = x.Length
+		Dim lenTotal = len * n
+		Dim newSize = size + lenTotal
+		EnsureCapacity(newSize)
+		separateBuffer()
+		ActiveBasic.Strings.ChrMove(VarPtr(chars[i + lenTotal]), VarPtr(chars[i]), (size - index) As SIZE_T)
+		Dim i As Long
+		For i = 0 To ELM(n)
+			x.CopyTo(0, chars, size + i * len, len)
+		Next
+		size = newSize
+		Return This
+	End Function
+
+
+	Function Insert(i As Long, x As *StrChar, index As Long, count As Long) As StringBuilder
+		rangeCheck(i)
+		If x = 0 Then
+			'Throw New ArgumentNullException
+			Debug
+		ElseIf index < 0 Or count < 0 Then
+			'Throw New ArgumentNullException
+			Debug
+		End If
+
+		Dim newSize = size + count
+		EnsureCapacity(newSize)
+		separateBuffer()
+		ActiveBasic.Strings.ChrMove(VarPtr(chars[i + count]), VarPtr(chars[i]), (size - i) As SIZE_T)
+		ActiveBasic.Strings.ChrCopy(VarPtr(chars[i]), VarPtr(x[index]), count As SIZE_T)
+		size = newSize
+		Return This
+	End Function
+
+Private
+	Sub insertCore(i As Long, s As String)
+		Dim newSize = size + s.Length
+		EnsureCapacity(newSize)
+		separateBuffer()
+		ActiveBasic.Strings.ChrMove(VarPtr(chars[i + s.Length]), VarPtr(chars[i]), (size - i) As SIZE_T)
+		s.CopyTo(0, chars, i, s.Length)
+		size = newSize
+	End Sub
+Public
+
+	Function Remove(startIndex As Long, length As Long) As StringBuilder
+		rangeCheck(startIndex, length)
+		separateBuffer()
+
+		Dim moveStart = startIndex + length
+		ActiveBasic.Strings.ChrMove(
+			VarPtr(chars[startIndex]), VarPtr(chars[moveStart]), (size - moveStart) As SIZE_T)
+		size -= length
+		Return This
+	End Function
+
+	Function Replace(oldChar As StrChar, newChar As StrChar) As StringBuilder
+		replaceCore(oldChar, newChar, 0, size)
+		Return This
+	End Function
+
+	Function Replace(oldStr As String, newStr As String) As StringBuilder
+		replaceCore(oldStr, newStr, 0, size)
+		Return This
+	End Function
+
+	Function Replace(oldChar As StrChar, newChar As StrChar, startIndex As Long, count As Long) As StringBuilder
+		rangeCheck(startIndex, count)
+		replaceCore(oldChar, newChar, startIndex, count)
+		Return This
+	End Function
+
+	Function Replace(oldStr As String, newStr As String, startIndex As Long, count As Long) As StringBuilder
+		rangeCheck(startIndex, count)
+		replaceCore(oldStr, newStr, startIndex, count)
+		Return This
+	End Function
+Private
+	Sub replaceCore(oldChar As StrChar, newChar As StrChar, start As Long, count As Long)
+		separateBuffer()
+		Dim i As Long
+		Dim last = ELM(start + count)
+		For i = start To last
+			If chars[i] = oldChar Then
+				chars[i] = newChar
+			End If
+		Next
+	End Sub
+
+	Sub replaceCore(oldStr As String, newStr As String, start As Long, count As Long)
+		If Object.ReferenceEquals(oldStr, Nothing) Then
+			'Throw ArgumentNullException
+			Debug
+		ElseIf oldStr.Length = 0 Then
+			'Throw ArgumentException
+			Debug
+		End If
+
+		Dim s = New StringBuilder(capacity, maxCapacity)
+		Dim curPos = 0 As Long
+		Do
+			Dim nextPos = ActiveBasic.Strings.ChrFind(VarPtr(chars[curPos]) As *StrChar, size As SIZE_T, StrPtr(oldStr), oldStr.Length As SIZE_T)
+			If nextPos = -1 As SIZE_T Then
+				Exit Sub
+			End If
+			
+			s.appendCore(chars, curPos, nextPos)
+			s.Append(newStr)
+			curPos += nextPos + oldStr.Length
+		Loop
+		chars = s.chars
+		size = s.size
+	End Sub
+
+Public
+	Override Function ToString() As String
+		chars[size] = 0
+		Return New String(This)
+	End Function
+
+	Const Function ToString(startIndex As Long, length As Long) As String
+		rangeCheck(startIndex, length)
+		Return New String(chars, startIndex, length)
+	End Function
+
+	Const Function Operator [](i As Long) As StrChar
+		Return Chars[i]
+	End Function
+
+	Sub Operator []=(i As Long, c As StrChar)
+		Chars[i] = c
+	End Sub
+
+	'Properties
+	Const Function Capacity() As Long
+		Return capacity
+	End Function
+
+	Sub Capacity(c As Long)
+		If c < size Or c > MaxCapacity Then 'sizeとの比較でcが負の場合も対応
+			'Throw ArgumentOutOfRangeException
+		End If
+		EnsureCapacity(c)
+	End Sub
+
+	Const Function Chars(i As Long) As StrChar
+		If i >= Length Or i < 0 Then
+			'Throw IndexOutOfRangeException
+			Debug
+		End If
+		Return chars[i]
+	End Function
+
+	Sub Chars(i As Long, c As StrChar)
+		If i >= Length Or i < 0 Then
+			'Throw ArgumentOutOfRangeException
+			Debug
+		End If
+		chars[i] = c
+	End Sub
+
+	Const Function Length() As Long
+		Return size
+	End Function
+
+	Sub Length(i As Long)
+		EnsureCapacity(i) 'iが適切な値かどうかの確認はこの中で行う
+		If size < i Then
+			ActiveBasic.Strings.ChrFill(VarPtr(chars[size]), (i - size + 1) As SIZE_T, 0 As StrChar)
+		End If
+		size = i
+	End Sub
+
+	Const Function MaxCapacity() As Long
+		Return maxCapacity
+	End Function
+
+	Function __Chars() As *StrChar
+		Return chars
+	End Function
+
+	Sub __Stringized()
+		stringized = True
+	End Sub
+
+Private
+	Sub initialize(capacity As Long, maxCapacity = LONG_MAX As Long)
+		If capacity < 0 Or maxCapacity < 1 Or maxCapacity < capacity Then
+			'Throw ArgumentOutOfRangeException
+		End If
+
+		If capacity = 0 Then
+			This.capacity = 1024
+		Else
+			This.capacity = capacity
+		End If
+
+		This.maxCapacity = maxCapacity
+		This.size = 0
+		This.chars = GC_malloc_atomic((This.capacity + 1) * SizeOf (StrChar))
+		If chars = 0 Then
+			'Throw OutOfMemoryException
+			Debug
+		End If
+
+	End Sub
+
+	Sub initialize(s As String, startIndex As Long, length As Long, capacity As Long, maxCapacity = LONG_MAX As Long)
+		StringBuilder.rangeCheck2(s.Length, startIndex, length)
+
+		initialize(Math.Max(capacity, length), maxCapacity)
+
+		If Not String.IsNullOrEmpty(s) Then
+			s.CopyTo(startIndex, chars, 0, length)
+			size = s.Length
+		End If
+	End Sub
+
+	Sub rangeCheck(index As Long)
+		If index < 0 Or index > size Then
+			'Throw ArgumentOutOfRangeException
+			Debug
+		End If
+	End Sub
+
+	Sub rangeCheck(startIndex As Long, count As Long)
+		StringBuilder.rangeCheck2(size, startIndex, count)
+	End Sub
+
+	Static Sub rangeCheck2(length As Long, startIndex As Long, count As Long)
+		'length < 0は判定に入っていないことに注意
+		If startIndex < 0 Or count < 0 Or startIndex + count > length Then
+			'Throw ArgumentOutOfRangeException
+			Debug
+		End If
+	End Sub
+
+	Sub separateBuffer()
+		If stringized Then
+			Dim newChars = GC_malloc_atomic(SizeOf (StrChar) * capacity) As *StrChar
+			ActiveBasic.Strings.ChrCopy(newChars, chars, capacity As SIZE_T)
+			chars = newChars
+			stringized = False
+		End If
+	End Sub
+
+	chars As *StrChar
+	maxCapacity As Long
+	capacity As Long
+	size As Long
+	stringized As Boolean
+End Class
+
+End Namespace 'Text
+End Namespace 'System
+
+'暫定
+Function StrPtr(sb As System.Text.StringBuilder) As *StrChar
+	Return sb.__Chars
+End Function
Index: Include/Classes/System/Text/index.ab
===================================================================
--- Include/Classes/System/Text/index.ab	(revision 272)
+++ Include/Classes/System/Text/index.ab	(revision 272)
@@ -0,0 +1,3 @@
+'Classes/System/Text/index.ab
+
+#require <Classes/System/Text/StringBuilder.ab>
