2013年5月13日月曜日

文字列の文字数を取得するには

文字列の文字数を取得するには、StringクラスのLengthプロパティ(Integer型)を使用。
Lengthプロパティは半角と全角を区別せずに1文字と数える。
        Dim s As String = "ABCDE"
        MessageBox.show(s.Length.ToString() & "文字です")

部分文字列を取り出すには
Dim  変数  As Char = 文字列.Chars(インデックス)
Dim  変数  As String = 文字列.Substring(開始位置,文字数)

       Dim s As String = "ABCDEF"
       TextBox1.Text = s.Chars(1).ToString()
       TextBox1.Text = s.Substring(1,4)
       TextBox1.Text = s.Substring(3)

部分文字列を削除/挿入するには
Dim  変数  As String = 文字列.Remove(削除位置,削除文字数)
Dim  変数  As String = 文字列.Remove(削除位置)
Dim  変数  As String = 文字列.Remove(挿入位置,挿入文字数)


   Dim s As String = "ABCDEF"
       TextBox1.Text = s.Remove(0,3)
       TextBox1.Text = s.Remove(2)
       TextBox1.Text = s.Insert(1,"ZX")

文字列を検索するには
Dim  変数  As Integer = 文字列.IndexOf(検索文字列)
Dim  変数  As Integer = 文字列.IndexOf(検索文字列,検索開始位置)

        Dim s As String = TextBox1.Text
        Dim i As Integer = s.IndexOf("検索")
        ListBox1.Item.Clear()
        Do While i < >  - 1
            ListBox1.Item.Add( ( i + 1 ).ToString() & " 文字目 ")
            i  = s.IndexOf("検索", i + 1)
        Loop


←←←VBからACCESSのマクロを動かす

Imports System.Data.OleDb
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop.Access

Private Sub Button1_Click...
   Dim myPath As String = My.Application.Info.DirectoryPath & "¥***.accdb"
   Dim AccObj As Object = CreateObject("Access.Application")

  With AccObj
     .OpenCurrentDatabase(myPath)
     .DoCmd.RunMacro("マクロ")
     .Quit()
 End With
 AccObj = Nothing
End Sub