เว็ป http://pivoke.net รวม Win32API ไว้จำนวนมาก
ตัวอย่าง
http://pinvoke.net/default.aspx/user32.ShowWindow
tu blog , programming C#,PHP,Java,VB.NET,VB,HTTP,Protocol
Showing posts with label dotnet. Show all posts
Showing posts with label dotnet. Show all posts
01 February 2011
26 April 2007
C# กับ Method Split String ครับ
ใครที่กำลังใช้ C# อยู่อาจเห็นว่า Function Split ใน C# นั้นแตกต่างจาก
VB.NET อยู่มาก คือว่า มันมี prarameter เป็น char
ถ้าต้องการให้ ใช้ String ในการแยก ข้อความ ให้ทำโดย ใช้ Function ของ Web นี้ครับ
http://community.sgdotnet.org/blogs/triplez/archive/2005/04/24/14627.aspx
หรือ อีกวิธีก็ใช้ Regex class , static function ดังตัวอย่างนี้ครับ
String s = "Test ==> do you like it ";
String [] buf = System.Text.RegularExpressions.Regex.Split( s , "==>" ) ;
ก็จะได้ ผลลัพท์ เป็น
buf[0] = "Test" ; buf[1]="do you like it " ; ครับ
วิธีนี้ใช้ได้กับ String s ส่วนมากแต่ไม่ทั้งหมดนะครั้บเนื่องจากถ้าเป็น Regulaexprersion เช่นแยกด้วย จุด (.) ต้องใส่เครื่องหมายเป็นดังนี้ครับ
"\." ลองอ่านเพิ่มอีกทีนะครับ
=======================
update 25 april 200 7
จากลองเล่น C# ดูแล้ว ปรากฏว่า String.Replace(String, String , Enum บางอย่าง );
มันใช้งานได้ นะครับ แต่ว่าต้อง กำหนด ประเภทวิธีการเปรียบเทียบก่อน (enum นั่นแหละ )
VB.NET อยู่มาก คือว่า มันมี prarameter เป็น char
ถ้าต้องการให้ ใช้ String ในการแยก ข้อความ ให้ทำโดย ใช้ Function ของ Web นี้ครับ
http://community.sgdotnet.org/blogs/triplez/archive/2005/04/24/14627.aspx
หรือ อีกวิธีก็ใช้ Regex class , static function ดังตัวอย่างนี้ครับ
String s = "Test ==> do you like it ";
String [] buf = System.Text.RegularExpressions.Regex.Split( s , "==>" ) ;
ก็จะได้ ผลลัพท์ เป็น
buf[0] = "Test" ; buf[1]="do you like it " ; ครับ
วิธีนี้ใช้ได้กับ String s ส่วนมากแต่ไม่ทั้งหมดนะครั้บเนื่องจากถ้าเป็น Regulaexprersion เช่นแยกด้วย จุด (.) ต้องใส่เครื่องหมายเป็นดังนี้ครับ
"\." ลองอ่านเพิ่มอีกทีนะครับ
=======================
update 25 april 200 7
จากลองเล่น C# ดูแล้ว ปรากฏว่า String.Replace(String, String , Enum บางอย่าง );
มันใช้งานได้ นะครับ แต่ว่าต้อง กำหนด ประเภทวิธีการเปรียบเทียบก่อน (enum นั่นแหละ )
ตัวอย่างการ ก้อบปี้ File ทั้ง Folder ด้วย VB.net กับ xcopy.exe ครับ
ตัวอย่างการ ก้อบปี้ File ทั้ง Folder ด้วย VB.net
กับ xcopy.exe ของ windows xp กันครับ
--------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not txEnvWhiteAbsPath.Text.EndsWith("\") Then
txEnvWhiteAbsPath.Text &= "\"
End If
If Not IsNumeric(txCdID.Text) Then
MsgBox("หมายเลขซีดีต้องเป็นตัวเลขเท่านั้น", MsgBoxStyle.Exclamation)
Exit Sub
End If
Dim sNewPath As String = txEnvWhiteAbsPath.Text & "Cd" & txCdID.Text.Trim
Try
MkDir(sNewPath)
Catch : End Try
'Dim p As New Process
Process.Start("Explorer.exe ", sNewPath)
Dim sCmd As String = "c:\xcopy.exe "
Dim sArgs As String = DriveListBox1.Text.Substring(0, 2) & " " & sNewPath & " /I /E /V"
Shell(sCmd & " " & sArgs, AppWinStyle.NormalFocus, True)
MsgBox("สร้าง Folder และคัดลอกข้อมูลแล้ว กรุณาเอาแผ่นซีดีออก" & vbCrLf & sNewPath)
' txCdID.Text = ""
End Sub
กับ xcopy.exe ของ windows xp กันครับ
--------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not txEnvWhiteAbsPath.Text.EndsWith("\") Then
txEnvWhiteAbsPath.Text &= "\"
End If
If Not IsNumeric(txCdID.Text) Then
MsgBox("หมายเลขซีดีต้องเป็นตัวเลขเท่านั้น", MsgBoxStyle.Exclamation)
Exit Sub
End If
Dim sNewPath As String = txEnvWhiteAbsPath.Text & "Cd" & txCdID.Text.Trim
Try
MkDir(sNewPath)
Catch : End Try
'Dim p As New Process
Process.Start("Explorer.exe ", sNewPath)
Dim sCmd As String = "c:\xcopy.exe "
Dim sArgs As String = DriveListBox1.Text.Substring(0, 2) & " " & sNewPath & " /I /E /V"
Shell(sCmd & " " & sArgs, AppWinStyle.NormalFocus, True)
MsgBox("สร้าง Folder และคัดลอกข้อมูลแล้ว กรุณาเอาแผ่นซีดีออก" & vbCrLf & sNewPath)
' txCdID.Text = ""
End Sub
Subscribe to:
Posts (Atom)
