//------------------------------------------------------------------------------ //--- 010 Editor v6.0.1 Script File // // File: DeleteLinesContaining.1sc // Authors: HTC - VinCSS company (a member of Vingroup) // Version: 1.0 // Purpose: Deletes all lines in the selection which contains specified word. // If no lines are selected all lines in the file will selected. // Category: Text // History: // 1.0 2020-06-19 HTC: Initial release. //------------------------------------------------------------------------------ // Trim all a string void StrTrimAll(string &strLine) { int i, len; len = Strlen(strLine); if (len > 0) { for (i = 0; (i < len) && IsCharWhitespace(strLine[i]); ++i); if (i > 0) { strLine = SubStr(strLine, i); } len = Strlen(strLine); for (i = len - 1; (i >= 0) && IsCharWhitespace(strLine[i]); --i); strLine[i + 1] = 0; } } void Main(void) { int64 i, startLine = -1, endLine = -1, count = 0; int lineSize; string strWord; string strLine; // Calculate start and end if (GetSelSize() > 0) { startLine = TextAddressToLine(GetSelStart()); endLine = TextAddressToLine(GetSelStart() + GetSelSize()); } else { startLine = 0; endLine = TextGetNumLines() - 1; } if ((startLine <= -1) || (endLine <= -1)) { return; } Assert(endLine >= startLine, "Invalid selected range or file in Hex mode"); strWord = InputString("Input the word in lines will be deleted", "Input", "sub_"); StrTrimAll(strWord); if (0 == Strlen(strWord)) { return; } // Check each line contains the strWord for (i = endLine; i >= startLine; i--) { // Read each line of the file lineSize = TextGetLineSize(i, true); TextReadLine(strLine, i, lineSize, true); if ((Strlen(strLine) > 0) && (Strstr(strLine, strWord) != -1)) { // Line contains the word need delete - delete that line DeleteBytes(TextLineToAddress(i), lineSize); count++; } } // Reset the selection if (GetSelSize() > 0) { int64 startPos = TextLineToAddress(startLine); int64 endPos = TextLineToAddress(endLine - count + 1); if ((startPos >= 0) && (endPos >= 0)) { SetSelection(startPos, endPos - startPos); SetCursorPos(endPos); } } // Show output StatusMessage("Deleted %d lines.", count); } Main();