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 /// summary> public class csuperstring {/// /// function brief description: Operator overload /// summary> /// left parameter param> /// right parameter param> /// text class returns> 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 /// summary> /// left parameter param> /// Right parameter param> /// text class returns> 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 /// summary> /// left parameter param> /// right parameter param> // / text class return Operator (CSUPERSTRING LEFT, CSUPERSTRING RIGHT) {byte [] btyright = new byte [Right.ilength]; // The declaration byte array (right parameter) Right.Memstm. Position = 0; // Place the right parameter stream position 0 Right.MemStrm.read (btyright, 0, btyright.length); // Translate the right parameter (string) into byte arrays left.MemStrm.Position = 0; // Set the left parameter stream position 0 left.MemStrm.write (btyright, 0, btyright.length); // Write the right parameter string to the stream left.itextLength = Right.itextLength; // Set the left parameter text length Left.ilength = right.ilength; // Set the left parameter number length
Return left; // Return to the left parameter}
/// /// function brief description: stream valid byte length /// summary> private int = 0; /// // / function brief description: Flow text length / // summary> private int itextLength = 0;
/// /// function brief description: Memory stream /// summary> Private MemoryStream MemStrM;
/// /// function brief description: Constructor /// summary> public csuperstring () {MEMSTRM = New MemoryStream (); // Initialization flow}
/// /// function brief: Constructor /// summary> /// Default length (in bytes) param> Public CSUPERSTRING (INT) DEFAULTLENGTH) {MEMSTRM = New MemoryStream (DefaultLength); // Initialization flow}
/// /// function brief description: attribute, byte length /// summary> public int layth {get {returningu;}}
/// /// function brief description: Property, text length /// summary> public int textLength {get {returnTextLength;}} /// // / function brief: Property, Flow length /// summary> 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 /// ///// param> 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 /// summary> /// Return String returns> 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 //// summary> /// file name param> 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 ///// summary> /// stream param> 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 /// summary> public void clear () {iLENGTH = 0; // Set the flow byte length to 0 item = 0; // will flow Text length is set to 0}}}