LumiSoft.Net.StreamLineReader.ReadLineString C# (CSharp) Méthode

ReadLineString() public méthode

Reads string line from stream. String is converted with specified Encoding property from byte[] line. NOTE: Returns null if end of stream reached.
public ReadLineString ( ) : string
Résultat string
        public string ReadLineString()
        {
            byte[] line = ReadLine();
            if(line != null){
                if(m_Encoding == null || m_Encoding == ""){
                    return System.Text.Encoding.Default.GetString(line);
                }
                else{
                    return System.Text.Encoding.GetEncoding(m_Encoding).GetString(line);
                }
            }
            else{
                return null;
            }
        }

Usage Example

        /// <summary>
        /// Deletes specified message from recycle bin.
        /// </summary>
        /// <param name="messageID">Message ID which to restore.</param>
        public static void DeleteRecycleBinMessage(string messageID)
        {
            using(FileStream fs = GetFile()){
                int              delRowCount = 0;
                StreamLineReader r           = new StreamLineReader(fs);
                long             pos         = fs.Position;
                string           line        = r.ReadLineString();
                while(line != null){
                    // Skip comment lines
                    if(!line.StartsWith("#")){
                        // Skip deleted row
                        if(line.StartsWith("\0")){
                            delRowCount++;
                        }
                        else{
                            string[] row = TextUtils.SplitQuotedString(line,' ');
                            // Delete row
                            if(row[0] == messageID){
                                string            user   = row[2];
                                string            folder = TextUtils.UnQuoteString(row[3]);

                                // Delete message
                                File.Delete(m_RecycleBinPath + messageID + ".eml");

                                // Delete row
                                byte[] linebytes = new byte[fs.Position - pos - 2];
                                fs.Position = pos;
                                fs.Write(linebytes,0,linebytes.Length);
                                fs.Position += 2; // CRLF
                                delRowCount++;
                                break;
                            }
                        }
                    }

                    pos  = fs.Position;
                    line = r.ReadLineString();
                }

                // There are many deleted rows, vacuum(remove deleted rows) flags database.
                if(delRowCount > 500){
                    Vacuum(fs);
                }
            }
        }
All Usage Examples Of LumiSoft.Net.StreamLineReader::ReadLineString