Ví dụ như:
String str = hello diendan congdongcviet
Xử lý theo kiểu:
+ Cắt chuỗi từ bên trái "hello", bên phải "congdongcviet", ở giữa "diendan";
+ Đảo, ghép chuỗi;
+ Xác định vị trí của kí tự trong chuỗi;
+ Đổi số thành chuỗi và ngược lại.
Có một đoạn code thuộc dạng bài tập tạo Client - Server bằng Socket, xử lý tuần tự ở chế độ có nối kết. Công việc là xử lý chuổi từ Client gửi lên Server, trả về chuỗi đã được xử lý. Đoạn này chỉ cắt được bên trái, giữa và bên phải thì em không làm được. Mong các anh gợi ý giúp. Em dùng JGreator Pro để dịch chương trình.
Server
Mã:
import java.net.*;
import java.io.*;
public class STCPEchoServer_Chuoi {
public final static int defaultPort =9999;
public static void main (String[] args) {
try{
ServerSocket ss = new ServerSocket(defaultPort);
while(true){
try{
Socket s = ss.accept();
OutputStream os = s.getOutputStream();
InputStream is = s.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
PrintWriter pw = new PrintWriter(os);
while(true){
String line = br.readLine();
if(line==null)break;
int i = line.indexOf(" ");
String str = line.substring(0,i);
System.out.println(line);
pw.println(str);
pw.flush();
}
}catch(IOException e){
System.out.print("Connection Error:"+e);
}
}
}catch(IOException e){
System.out.print("Server Creation Error:"+e);
}
}
}
Client
Mã:
import java.io.*;
import java.net.Socket;
public class TCPEchoClient_Chuoi {
public static void main (String[] args) {
try{
Socket s = new Socket("127.0.0.1",9999);
InputStream is = s.getInputStream();
InputStreamReader isk = new InputStreamReader(System.in);
BufferedReader brk = new BufferedReader(isk);
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
OutputStream os = s.getOutputStream();
PrintWriter pw = new PrintWriter(os);
while(true){
try{
String line = brk.readLine();
boolean k = line.equals("thoat");
if(k==true)break;
pw.println(line);
pw.flush();
String line1 = br.readLine();
System.out.println(line1);
}catch(IOException ie){
System.out.print("Loi: Khong tao duoc socket");
}
}
s.close();
}catch(IOException ie){
System.out.print("Loi: Khong tao duoc socket1");
}
}
}
Bất chấp những lầm tưởng phổ quát, hồ hết những người có âm đạo đều khó lên đỉnh khi bị kích thích âm đạo. Tuy nhiên, điều đó không có tức thị nó không thể vui được! Việc xâm nhập vào âm đạo bằng...
Quý bà giải tỏa bằng việc kích...