
正文
vb.net正则提取路径 vbs正则表达式怎么选择要用的字符
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
VB.NET 正则表达式提取
^Host:\s(.+)$
^表示是一行的开始,Host:是你要匹配的内容中固定的部分(我是这么认为的),\s表示有一个空格或者Tab,(.+)表示任意字符,就是匹配hm.baidu.com的,$表示是行的结尾,匹配结果中提取到的就是hm.baidu.com了。
相关问答
Q1: vb.net怎么实现点击下载,获取文件路径并下载
下载,直接通过url读取文件,然后Response.OutputStream.Write()数据
下面提供个下载的静态方法,是C#的,供参考:
/// summary
/// 下载文件
/// /summary
/// param name="fileName"下载的文件名称(包括扩展名)/param
/// param name="filePath"下载文件的绝对路径/param
public static void DownFile(string fileName, string filePath)
{
//打开要下载的文件,并把该文件存放在FileStream中
System.IO.FileStream Reader = System.IO.File.OpenRead(filePath);
//文件传送的剩余字节数:初始值为文件的总大小
long Length = Reader.Length;
HttpContext.Current.Response.Buffer = false;
HttpContext.Current.Response.AddHeader("Connection", "Keep-Alive");
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.Charset = "utf-8";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(fileName));
HttpContext.Current.Response.AddHeader("Content-Length", Length.ToString());
byte[] Buffer = new Byte[10000];//存放欲发送数据的缓冲区
int ByteToRead; //每次实际读取的字节数
while (Length 0)
{
//剩余字节数不为零,继续传送
if (HttpContext.Current.Response.IsClientConnected)
{
//客户端浏览器还打开着,继续传送
ByteToRead = Reader.Read(Buffer, 0, 10000); //往缓冲区读入数据
HttpContext.Current.Response.OutputStream.Write(Buffer, 0, ByteToRead);
//把缓冲区的数据写入客户端浏览器
HttpContext.Current.Response.Flush(); //立即写入客户端
Length -= ByteToRead;//剩余字节数减少 }
else
{
//客户端浏览器已经断开,阻止继续循环
Length = -1;
}
} //关闭该文件
Reader.Close();
}
QQ:121一九五五121
Q2: vb.net从文件路径中获取文件名
获取方法vb.net正则提取路径,参考实例如下vb.net正则提取路径:
'获取路径名各部分: 如vb.net正则提取路径: c:\dir1001\aaa.txt
'获取路径路径 c:\dir1001\
Public Function GetFileName(FilePathFileName As String) As String '获取文件名 aaa.txt
On Error Resume Next
Dim i As Integer, J As Integer
i Len(FilePathFileName)
J InStrRev(FilePathFileName, "\")
GetFileName Mid(FilePathFileName, J + 1, i)
End Function
''获取路径路径 c:\dir1001\
Public Function GetFilePath(FilePathFileName As String) As String '获取路径路径 c:\dir1001\
On Error Resume Next
Dim J As Integer
J InStrRev(FilePathFileName, "\")
GetFilePath Mid(FilePathFileName, 1, J)
End Function
'获取文件名但不包括扩展名 aaa
Public Function GetFileNameNoExt(FilePathFileName As String) As String '获取文件名但不包括扩展名 aaa
On Error Resume Next
Dim i As Integer, J As Integer, k As Integer
i Len(FilePathFileName)
J InStrRev(FilePathFileName, "\")
k InStrRev(FilePathFileName, ".")
If k 0 Then
GetFileNameNoExt Mid(FilePathFileName, J + 1, i - J)
Else
GetFileNameNoExt Mid(FilePathFileName, J + 1, k - J - 1)
End If
End Function
'===== '获取扩展名 .txt
Public Function GetFileExtName(FilePathFileName As String) As String '获取扩展名 .txt
On Error Resume Next
Dim i As Integer, J As Integer
i Len(FilePathFileName)
J InStrRev(FilePathFileName, ".")
If J 0 Then
GetFileExtName ".txt"
Else
GetFileExtName Mid(FilePathFileName, J, i)
End If
End Function
Q3: VB.net 正则表达式提取网页内容
楼上的说法不对,正则式的作用就是匹配未知的一些东西,可以提取.
代码如下:
-----------
Imports System.Text.RegularExpressions
dim sHtml as string=网页内容'自己想办法获取,比如Doc.Body.InnerHtml
dim sResult1 as string=""'“听过哪些草原歌”
sResult1=Regex.Match(sHtml, "\[aA]{1}[ ]{1}class\=t[ ]{1}href.+\(.+)\\/[aA]{1}\").Groups(1).Value
'其余类推...
'保存进文件
大哥把分给我吧.求你了.祝你好运中500万
Q4: vb.net文件关联后获取文件路径
我没有设置关联,只是把文件拖到程序文件上打开,应该是一样的。
主要是看程序启动时的命令行参数My.Application.CommandLineArgs,里面包括要打开的文件路径。
在Sub Main 或者 启动窗口的Load事件里添加代码
If My.Application.CommandLineArgs.Count 0 AndAlso My.Computer.FileSystem.FileExists(My.Application.CommandLineArgs(0)) Then‘参数不为空且文件存在
Dim s As New IO.StreamReader(My.Application.CommandLineArgs(0))
MsgBox(s.ReadToEnd)
End If
你还可以处理更多的命令行参数。
关于命令行参数
关于vb.net正则提取路径和vbs正则表达式怎么选择要用的字符的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







