zoukankan      html  css  js  c++  java
  • delphi Berlin10.1 string、AnsiString及Tbytes等之间的转换

    1.类型说明

    Byte:Represents an 8-bit unsigned integer type.

    [PByte:Is a pointer to a Byte.]

    Char:Represents a word-sized (16-bits) character type

    AnsiChar:Represents a byte-sized (8-bits) character type

    WideChar:Represents a word-sized (16-bits) character type.

    [PChar:Defines a null-terminated string]

    [PAnsiChar:Defines a null-terminated ANSI string.]

    String:Represents an alias for the generic UnicodeString type.

    AnsiString:Represents a dynamically allocated string whose maximum length is limited only by available memory.

    WideString:A null-terminated string of wide characters, with no reference counting.

    [PString:Is a pointer to a String.]

    [PAnsiString:Is a pointer to an AnsiString.]

    TBytes:declares an array of Bytes.

    2.指针

     1         var

     2           X, Y: Integer;  // X and Y are Integer variables

     3           P: ^Integer;     // P points to an Integer

     4         begin

     5           X := 17;      // assign a value to X

     6           P := @X;      // assign the address of X to P

     7           Y := P^;      // dereference P; assign the result to Y

     8         end;

    type

      PInteger = ^Integer;

    var

      R: Single;

      I: Integer;

      P: Pointer;

      PI: PInteger;

    begin

      ...

      P := @R;

      PI := PInteger(P);

      I := PI^;

    end;

    3.一些点

    SizeOf:Returns the number of bytes occupied by a variable or type.

    Length:Returns the number of characters in a string or of elements in an array. 

    Move:Copies bytes from a source to a destination. e.g.: Move(PChar(@arrBuf[0])^, LPChar^, aSectorNum * 512);

    ByteLength:Returns the length of a given string in bytes.

    GetBytes:Encodes a set of characters into a sequence of bytes

    FillChar:Fills contiguous bytes with a specified value.

    4.转换

    TBytes -> PChar :     LPChar :=  PChar(LTBytes);

    PChar -> TBytes:LTBytes := BytesOf(LPChar);

    TBytes -> Array of AnsiChar:move(LTBytes[i],LArrayOfAnsiChar[k]);

    Array of AnsiChar -> string:LString := StringOf(BytesOf(LArrayOfAnsiChar));

  • 相关阅读:
    3.struts2接收页面传参的三种方式
    2.struts2访问web资源(在struts2中获取session,request等等)
    1.struts2原理和入门程序
    3.springMVC+spring+Mybatis整合Demo(单表的增删该查,这里主要是贴代码,不多解释了)
    2.springMVC+spring+Mybatis整合
    1.springMVC+spring+Mybatis的整合思路
    clipboard
    SDN&NFV
    linux命令速查
    todo
  • 原文地址:https://www.cnblogs.com/keynexy/p/5919962.html
Copyright © 2011-2022 走看看