Enhance string

zhaozj2021-02-16  48

A custom class for large-scale string connections, such as splicing SQL statements. Implement with flow technology, very good!!

Using system; using system.text; using system.windows.forms;

Namespace Superstring {///

/// Created by: superhood /// Content Description: Enhanced String Category /// public class csuperstring {/// /// function brief description: Operator overload /// /// left parameter /// right parameter /// text class public static CSuperString operator (string left, CSuperString Right) {byte [] btyLeft = Encoding.Default.GetBytes (left); // returns an array of the left argument byte [] btyRight = new byte [Right.iLength] ; // Return the right parameter array Right.itextLength = left.length; // Set the right parameter text length Right.ilength = btyleft.length btyright.Length; // Set the right parameter byte length Right.MemStrm.Position = 0 ; // Set the right parameter flow position 0 Right.MemStrm.read (btyright, 0, btyright.length); // Read the right parameter data

Right.MemStrm.Position = 0; // Position the right parameter stream position 0 Right.MemStrm.write (Btyleft, 0, btyft.length); // Write the string (byte array) Right.MemStrm. Write (btyright, 0, btyright.length); // Write the right parameter original information (after the left parameter string)

Return Right; // Return to the right parameter}

///

/// function brief description: operator overload /// /// left parameter /// Right parameter /// text class public static csuperstring Operator (CSUPERSTRING LEFT, STRING RIGHT) {byte [] btyright = encoding.default.getBytes (Right); // Right parameters (String) Convert to byte arrays left.MemStrm.Position = left.ilength; // Set the position of the left paragraph stream Left.MemStrm.Write (BTyRight, 0, btyright.length); // Write the right parameter string Enter

LEFT.ITEXTLENGTH = Right.Length; // Set the left parameter text length Left.ilength = btyright.length; // Set the left parameter number length return left parameter length Return Left; // Return to the left parameter} ///

// / Function brief introduction: operator overload /// /// left parameter /// right parameter // / text class

Return left; // Return to the left parameter}

///

/// function brief description: stream valid byte length /// private int = 0; /// // / function brief description: Flow text length / // private int itextLength = 0;

///

/// function brief description: Memory stream /// Private MemoryStream MemStrM;

///

/// function brief description: Constructor /// public csuperstring () {MEMSTRM = New MemoryStream (); // Initialization flow}

///

/// function brief: Constructor /// /// Default length (in bytes) Public CSUPERSTRING (INT) DEFAULTLENGTH) {MEMSTRM = New MemoryStream (DefaultLength); // Initialization flow}

///

/// function brief description: attribute, byte length /// public int layth {get {returningu;}}

///

/// function brief description: Property, text length /// public int textLength {get {returnTextLength;}} /// // / function brief: Property, Flow length /// public int Capacity {get {return memstrm.capacity;} set {if (value> = iLength) MEMSTRM.CAPACITY = VALUE; Else MemStrm.capacity = iLsength;}}

///

/// function brief: Add a string to the class /// public void addstring (string date) {BYTE [] btydate = encoding.default.getbytes (date); // String Convert to byte array MEMSTRM.POSION = ienngth; // Set the position of the stream MEMSTRM.WRITE (BtyDate, 0, btydate.length); // String writing stream

ITextLength = Date.Length; // Set text length iLength = btydate.Length; // Set byte length}

///

/// function brief: Return to text /// /// Return String public override string toString () {MEMSTRM.POSITION = 0; /////// Set the stream Byte [] btydate = new byte []l "; // declaration byte array MEMSTRM.READ (btydate, 0, ilength); // Read the stream content into the array eNCoding.default.getstring (btydate); // convert the byte array into a string and return}

///

/// function brief description: Write string //// /// file name public void WriteTofile (String filename) {FileStream Strm = New FileStream (FileName, FileMode.Openorcreate, FileAccess.write); // Initialization File Sfit // Judgment flow length Used to determine if there is redundant information if there is redundant information if (MemStrm.length> ilength) {// MemStrM.Position = 0; // Setting the stream Byte [] btydate = new byte []l "; // declaration byte array MEMSTRM.READ (btydate, 0, ilength); // Read the stream content into the array STRM. Write (btydate, 0, ilength); // Write the stream content} else {// No MemStrm.Writto (STRM); // Write the flow of the text}

Strm.close (); // Close file}

///

/// function brief description: write string ///// /// stream public void Writtle (stream strm) { / / Judgment the flow length is used to determine if there is redundant information if (MemStrm.length> ilength) {// has memstrm.position = 0; // Setting the stream BYTE [] btydate = new byte []ens]; // A declaration byte array MEMSTRM.READ (btydate, 0, ilength); // read the stream content into the array strm.write (btydate, 0, ilength); // Write the array content to another} else {// There is no MEMSTRM.WRITETO (STRM); // Write the text in the stream to another.}

///

/// function brief description: Clear flow /// public void clear () {iLENGTH = 0; // Set the flow byte length to 0 item = 0; // will flow Text length is set to 0}}}

转载请注明原文地址:https://www.9cbs.com/read-22684.html

New Post(0)