获取搜索中的所有文字? [英] get all text in the search ?

查看:86
本文介绍了获取搜索中的所有文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在字符串到字符串之间得到所有字眼

例如:

in richtextbox =bhram中有单词= good best& bhram = ckashdkjashd& bhram = kdjsakljd

现在得到bhram = to& ???

i使用此代码:

i wanna get all word in between string to string
for example :
in richtextbox = "there is word in bhram=good best& bhram=ckashdkjashd & bhram=kdjsakljd "
now get every word between bhram= to & ???
i use this code :

Public Function GetBetween(ByVal haystack As String, ByVal needle As String, ByVal needle_two As String) As String
      Dim istart As Integer = InStr(haystack, needle)
      If istart > 0 Then
          Dim istop As Integer = InStr(istart, haystack, needle_two)
          If istop > 0 Then
              Dim value As String = haystack.Substring(istart + Len(needle) - 1, istop - istart - Len(needle))
              Return value
          End If
      End If
      Return Nothing
  End Function



然后


then

dim word as string = richtextbox1.text 
Dim sss As String = GetBetween(word , "bhram=", "&")
textbox1.text = sss





i想要介于bhram =到&之间

像这样的照片



http://im34.gulfup.com/VPa5V.jpg



i wanna get between "bhram=" to "&"
like this in picture

http://im34.gulfup.com/VPa5V.jpg

推荐答案

有两种方法可以做到这一点:第一种方法是获取第一个字符串的索引,然后获取第二个字符串的索引,并提取它们之间的子字符串。

There are two ways to do this: The first is to get the index of the first string, then the index of the second string, and extract the substring between them.
Dim s As String = "there is word in bhram=good best& bhram=ckashdkjashd & bhram=kdjsakljd "
Dim searchStart As String = "bhram="
Dim searchEnd As String = "&"
Dim start As Integer = s.IndexOf(searchStart)
Dim [end] As Integer = s.IndexOf(searchEnd, start)
If start > -0 AndAlso [end] >= 0 Then
    start += searchStart.Length
    Dim extract As String = s.Substring(start, [end] - start)
End If

这将提取字符串最好的。



另一种方法是使用正则表达式,通常我会推荐它,但是使用变量字符串它是PITA,因为你必须确保你搜索的字符串不包含正则表达式的字符,然后将它们转义。

This extracts the string "good best".

The other way to do this uses a regex, and normally I would recommend it, but with variable strings it''s a PITA because you have to make sure that the strings you search for do not contain regex-aware characters, and escape them.


我有提取两种东西的功能

i have function to extract both something
Public Function GetBetween(ByVal haystack As String, ByVal needle As String, ByVal needle_two As String) As String
      Dim istart As Integer = InStr(haystack, needle)
      If istart > 0 Then
          Dim istop As Integer = InStr(istart, haystack, needle_two)
          If istop > 0 Then
              Dim value As String = haystack.Substring(istart + Len(needle) - 1, istop - istart - Len(needle))
              Return value
          End If
      End If
      Return Nothing
  End Function





i想全力以赴列表框不是一个!!怎么做,PLZ?



i wanna get all in listbox not one !! how do it , plz ?


这篇关于获取搜索中的所有文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆