VisualBasic(用法)
Dim
instance
As
String
Dim
startIndex
As
Integer
Dim
length
As
Integer
Dim
returnValue
As
String
returnValue
=
instance.Substring(startIndex,length)
C#
public
string
Substring(
int
startIndex,
int
length
)
Imports
System
Public
ClassSubStringTest
Class
SubStringTest
Public
Shared
SubMain()
Sub
Main()
Dim
info
As
String
()
=
{
"
Name:FelicaWalker
"
,
"
Title:Mz.
"
,
"
Age:47
"
,
"
Location:Paris
"
,
"
Gender:F
"
}
Dim
found
As
Integer
=
0
Console.WriteLine(
"
Theinitialvaluesinthearrayare:
"
)
Dim
s
As
String
For
Each
s
In
info
Console.WriteLine(s)
Next
s
Console.WriteLine(
"
{0}Wewanttoretrieveonlythekeyinformation.Thatis:
"
,Environment.NewLine)
For
Each
s
In
info
found
=
s.IndexOf(
"
:
"
)
Console.WriteLine(s.Substring((found
+
1
)).Trim())
Next
s
EndSub
'
Main
EndClass
'
SubStringTest
C#
using
System;
public
class
SubStringTest
...
{
public
static
void
Main()
...
{
string
[]info
=
...
{
"
Name:FelicaWalker
"
,
"
Title:Mz.
"
,
"
Age:47
"
,
"
Location:Paris
"
,
"
Gender:F
"
}
;
int
found
=
0
;
Console.WriteLine(
"
Theinitialvaluesinthearrayare:
"
);
foreach
(
string
s
in
info)
Console.WriteLine(s);
Console.WriteLine(
"
{0}Wewanttoretrieveonlythekeyinformation.Thatis:
"
,Environment.NewLine);
foreach
(
string
s
in
info)
...
{
found
=
s.IndexOf(
"
:
"
);
Console.WriteLine(s.Substring(found
+
1
).Trim());
}
}
}
平台
<supportedplatforms xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5"></supportedplatforms>Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition