C# と VB.NET の質問掲示板

ASP.NET、C++/CLI、Java 何でもどうぞ

ログ内検索
  • キーワードを複数指定する場合は 半角スペース で区切ってください。
  • 検索条件は、(AND)=[A かつ B] (OR)=[A または B] となっています。
  • [返信]をクリックすると返信ページへ移動します。
キーワード/ 検索条件 /
検索範囲/ 強調表示/ ON (自動リンクOFF)
結果表示件数/ 記事No検索/ ON
大文字と小文字を区別する

No.65033 の関連記事表示

<< 0 >>
■65033  Re[28]: 【VB2005、VB.NET】構造体のコピーについて
□投稿者/ コンバート後に悩む人 -(2013/01/30(Wed) 11:57:26)
    2013/01/30(Wed) 11:57:58 編集(投稿者)

    開始位置のパラメータを追加した別建てのメソッドを作成しました。
    以下のような感じでしょうか。

    #前述の話題ですが、Midだから+1ですよね。substringでしたら0スタートなので+1の心配はしなくてよいということをすっかり失念してました。


    Dim a5 As AAA = StructureFromText(Of AAA)(strW)
    Dim b5 As BBB = StructureFromText(Of BBB)(strW, Len(a5))


    '指定された文字列を、VBFixedString 属性の付いたフィールドに順次格納した値を返します。
    Public Function StructureFromText(Of T As Structure)(ByVal str As String, ByVal intStart As Integer) As T
    'RuntimeHelpers.GetObjectValue 対策の為、ValueType で受ける
    Dim newValue As ValueType = StructureFromText
    Dim pos As Integer = 1
    For Each f As FieldInfo In newValue.GetType().GetFields()
    Dim attributes() As Object = f.GetCustomAttributes(GetType(VBFixedStringAttribute), False)
    If attributes.Length <> 0 Then
    Dim attr As VBFixedStringAttribute = DirectCast(attributes(0), VBFixedStringAttribute)
    Dim value As String = Strings.Mid(str & StrDup(attr.Length, " "c), intStart + pos, attr.Length)
    f.SetValue(newValue, value)
    pos += attr.Length
    End If
    Next
    Return DirectCast(newValue, T)
    End Function
記事No.64946 のレス /過去ログ109より / 関連記事表示
削除チェック/



<< 0 >>

パスワード/

- Child Tree -