预览模式: 普通 | 列表

VB.NET字符串函数

1:字符串函数


StrComp 比较两个字符串

StrConv 转换字符串

InStrRev、StrReverse 翻转字符串

查看更多...

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 788

c# 保存文本文件

 

C#代码
  1. private void btSave_Click(object sender, EventArgs e)  //保存txt文件  
  2. {  
  3.                 saveFileDialog1.Filter = ("文本文件(*.txt)|*.txt");  //创建一个筛选器  
  4.                 if (saveFileDialog1.ShowDialog() == DialogResult.OK)  //判断按下的是保存还是取消  
  5.                 {  
  6.                     string path = saveFileDialog1.FileName;  //获得文件名和路径  
  7.                     using (StreamWriter sw = new StreamWriter(path, false))  //保存文件到指定路径  
  8.                     {  
  9.                         sw.WriteLine(txtNote.Text);  
  10.                     }  
  11. }  
  12.   
  13.    
  14.   
  15. private void btOpen_Click(object sender, EventArgs e)  //打开txt文件  
  16. {  
  17.             openFileDialog1.Filter = ("文本文件(*.txt)|*.txt");  //创建一个筛选器  
  18.             if (openFileDialog1.ShowDialog() == DialogResult.OK)  //判断按下的是打开还是取消  
  19.             {  
  20.                 string path = openFileDialog1.FileName;  //获得文件名和路径  
  21.                 using (StreamReader sr = new StreamReader(path, Encoding.UTF8))  //打开文件  
  22.                 {  
  23.                     txtNote.Text = sr.ReadToEnd();  
  24.                 }  
  25.             }  
  26. }  
 C#中StreamWriter类使用总结

1、使用的命名空间是:System.IO;
2、用来将字符串写入文件。
常用属性
  AutoFlush:获取或设置一个值,该值指示是否 System.IO.StreamWriter 将其缓冲区刷新到基础流在每次调用后 System.IO.StreamWriter.Write(System.Char)。
  Encoding:获取在其中写入输出的 System.Text.Encoding。
常用方法:
  WriteLine():写入文件,并且换行。
  Write():多种重写方式,具体可以查VS文档。
  Dispose():释放由 System.IO.StreamWriter 占用的非托管资源,还可以另外再释放托管资源。
  Flush():清理当前写入器的所有缓冲区,并使所有缓冲数据写入基础流。
  Close():关闭流。
使用简单示例:

 
C#代码
  1. string str = "Hello";  
  2. string path = @"D:dataWrite.txt";  
  3. // path:写入文件的路径,append:true 若要将数据追加到该文件; false 覆盖该文件。 如果指定的文件不存在,该参数无效,且构造函数将创建一个新文件。  
  4. StreamWriter sr = new StreamWriter(path,true,Encoding.Default);  // 保留文件原来的内容  
  5. sr.WriteLine(str);  
  6. sr.Flush();  // 清空缓存  
  7. sr.WriteLine(str);    

Tags: c#

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 519

C#遍历浏览某个文件夹下的所有文件

C#遍历浏览某个文件夹下的所有文件,方法如下:

C#代码
  1. //C#遍历指定文件夹中的所有文件  
  2.             DirectoryInfo TheFolder = new DirectoryInfo(path);  
  3.             if (!TheFolder.Exists)  
  4.                 return;  
  5.   
  6.             //遍历文件  
  7.             foreach (FileInfo NextFile in TheFolder.GetFiles())  
  8.             {  
  9.                 if (NextFile.Name == "0-0-11.grid")  
  10.                     continue;  
  11.           // 获取文件完整路径  
  12.                 string heatmappath = NextFile.FullName;               }  

 

Tags: c#

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 431

Cefsharp获取网站Cookie

 两个方案

1,获取js内容的方式

        {

            Task<CefSharp.JavascriptResponse> t = webBrower.EvaluateScriptAsync("document.cookie");

查看更多...

Tags: cefsharp

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 595

VB.NET模拟鼠标事件

Inherits System.Windows.Forms.Form

Declare Auto Sub mouse_event Lib "user32" (ByVal dwFlags As Int32, ByVal dx As Int32, ByVal dy As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As IntPtr)

Const MOUSEEVENTF_MOVE As Int32 = &H1 ' mouse move
Const MOUSEEVENTF_LEFTDOWN As Int32 = &H2 ' left button down
Const MOUSEEVENTF_LEFTUP As Int32 = &H4 ' left button up
Const MOUSEEVENTF_RIGHTDOWN As Int32 = &H8 ' right button down
Const MOUSEEVENTF_RIGHTUP As Int32 = &H10 ' right button up
Const MOUSEEVENTF_MIDDLEDOWN As Int32 = &H20 ' middle button down
Const MOUSEEVENTF_MIDDLEUP As Int32 = &H40 ' middle button up
Const MOUSEEVENTF_ABSOLUTE As Int32 = &H8000 ' absolute move
Const MOUSEEVENTF_WHEEL As Int32 = &H800 ' wheel button rolled

' Simulate moving the mouse to the center of the
' PictureBox and clicking.
Private Sub cmdClick_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdClick.Click
Dim cur_x As Single
Dim cur_y As Single
Dim dest_x As Single
Dim dest_y As Single

查看更多...

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 457

VB.net读写二进制数据方法

一、二进制文件读写

1、写二进制数据到指定目录


dim barray() as byte
dim strFileName as string
My.Computer.FileSystem.WriteAllBytes(strFileName, barray, False)
==>将barray字节数组中的数据创建在strFilename目录文件下,存储格式为二进制,False表示不添加,直接覆盖创建。

 

查看更多...

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 463

vb.net 中功能强大的Tostring()

功能强大的Tostring()

//2007年4月24日
this.TextBox6.Text = System.DateTime.Now.ToString("D");
//2007-4-24
this.TextBox7.Text = System.DateTime.Now.ToString("d");

//2007年4月24日 16:30:15
this.TextBox8.Text = System.DateTime.Now.ToString("F");
//2007年4月24日 16:30
this.TextBox9.Text = System.DateTime.Now.ToString("f");

//2007-4-24 16:30:15
this.TextBox10.Text = System.DateTime.Now.ToString("G");
//2007-4-24 16:30
this.TextBox11.Text = System.DateTime.Now.ToString("g");

查看更多...

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 439

VB.NET中如何动态创建控件

Option Explicit
Private WithEvents NewTextBox As TextBox
'通过使用WithEvents关键字声明一个对象变量为新的命令按钮

Private Sub Command1_Click()
If NewTextBox Is Nothing Then
Set NewTextBox = Controls.Add("VB.TextBox", "cmdNew", Form1)
NewTextBox.Move 200, 200
NewTextBox.Width = Form1.Width - 450
NewTextBox.Height = Form1.Height - 1400
NewTextBox.Visible = True
End If
End Sub

Private Sub Command2_Click()
If NewTextBox Is Nothing Then
Exit Sub
Else
Controls.Remove NewTextBox
Set NewTextBox = Nothing
End If
End Sub

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 394

VB.net线程传递参数四种方法

Thread线程启动方法,一般来说要么是一个无参数的方法,要么是一个带有object参数的方法并且在Start时传递参数的值。
但是我们可以利用一些技巧给方法传递不受限制的参数。这些方法又可以在实际使用过程相互融合。
方法简单直接上代码,供君参考。

Imports System.Threading Module Module1 Sub Main() '第一种:在Start中传递参数值,但方法中的参数类型需为object类型 Dim t1 As New Thread(AddressOf CountNumber) t1.Start(10) '第二种:通过Lambda表达式创建线程,可以传递任意的参数 Dim t2 As New Thread(Sub() PrintNumber(20) End Sub) t2.Start() '第三种:通过实例化类来传递参数,然后调用类方法 Dim c As New Count(10) Dim t3 As New Thread(AddressOf c.CountNumber) t3.Start() '第四种:通过传递类或结构,以达到向方法传递多个参数 Dim p As New Person() With { .FirstName = "严", .LastName = "查散" } Dim t4 As New Thread(AddressOf ShowName) t4.Start(p) Console.Read() End Sub '传递单个参数 Private Sub CountNumber(number As Object) Dim sum As Integer For i As Integer = 1 To Integer.Parse(number) sum += i Next Console.WriteLine(sum) End Sub '传递非object参数 Private Sub PrintNumber(number As Integer) Console.WriteLine(number) End Sub '把方法包装成类,在实例化时传递参数 Class Count Dim number As Integer Sub New(number As Integer) Me.number = number End Sub Public Sub CountNumber() Dim sum As Integer For i As Integer = 1 To Integer.Parse(number) sum += i Next Console.WriteLine(sum) End Sub End Class '传递一个类或结构达到传递多个参数 Private Sub ShowName(person As Object) Dim myPerson As Person = CType(person, Person) Console.WriteLine(myPerson.FirstName & myPerson.LastName) End Sub Class Person Public Property FirstName As String Public Property LastName As String End Class End Module

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 3025

Function GetWebCode(ByVal strURL As String) As String
Dim httpReq As System.Net.HttpWebRequest
Dim httpResp As System.Net.HttpWebResponse
Dim httpURL As New System.Uri(strURL)
Dim ioS As System.IO.Stream, charSet As String, tCode As String
Dim k() As Byte
ReDim k(0)
Dim dataQue As New Queue(Of Byte)
httpReq = CType(WebRequest.Create(httpURL), HttpWebRequest)
Dim sTime As Date = CDate("1990-09-21 00:00:00")
httpReq.IfModifiedSince = sTime
httpReq.Method = "GET"
httpReq.Timeout = 7000

Try
httpResp = CType(httpReq.GetResponse(), HttpWebResponse)
Catch
Debug.Print("weberror")
GetWebCode = "<title>no thing found</title>" : Exit Function
End Try
'以上为网络数据获取
ioS = CType(httpResp.GetResponseStream, Stream)
Do While ioS.CanRead = True
Try
dataQue.Enqueue(ioS.ReadByte)
Catch
Debug.Print("read error")
Exit Do
End Try
Loop
ReDim k(dataQue.Count - 1)
For j As Integer = 0 To dataQue.Count - 1
k(j) = dataQue.Dequeue
Next
'以上,为获取流中的的二进制数据
tCode = Encoding.GetEncoding("UTF-8").GetString(k) '获取特定编码下的情况,毕竟UTF-8支持英文正常的显示
charSet = Replace(GetByDiv2(tCode, "charset=", """"), """", "") '进行编码类型识别
'以上,获取编码类型
If charSet = "" Then 'defalt
If httpResp.CharacterSet = "" Then
tCode = Encoding.GetEncoding("UTF-8").GetString(k)
Else
tCode = Encoding.GetEncoding(httpResp.CharacterSet).GetString(k)
End If
Else
tCode = Encoding.GetEncoding(charSet).GetString(k)
End If
Debug.Print(charSet)
'Stop
'以上,按照获得的编码类型进行数据转换
'将得到的内容进行最后处理,比如判断是不是有出现字符串为空的情况
GetWebCode = tCode
If tCode = "" Then GetWebCode = "<title>no thing found</title>"
End Function

将如上代码复制,并引用:
Imports System.Net
Imports System.IO
Imports System.Text.Encoding
Imports System.Text

然后,就可以使用这个代码完成网页源代码下载的工作了。

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 394

cefsharp 禁止图片加载

只需要添加一句话就可以实现此功能


chromeBrowser.BrowserSettings.ImageLoading = CefState.Disabled;

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 464

 广告位

↑返回顶部↑