Looking for DOS command to create file listing of a folder and its sub-folders into a text file? Here are the simple steps. Before using the commands, do below steps Open Command Prompt Goto the folder path from where you want to list the files. Run below commands In below examples, C:\Main-Folder\Folder> is the folder path […]
If you want to remove extra whitespaces from start and end of a string, use strip() method in Python. strip() method removes all default whitespaces (spaces and tabs \t) and returns the copy of the string. Python code to strip trailing whitespaces from string
string = " xyz is equal to xyz " # string with whitespaces (spaces and tabs)
print "string with trailing whitespaces is \"" + string + "\"" # printing string with trailing whitespaces
string = string.strip() # strip trailing whitespaces
print "string after stripping trailing whitespaces is \"" + string + "\"" # printing the string after stripping trailing whitespaces
Note: Code works in both Python 2 and 3 Output […]
Python code to get the position of next or second occurrence of a sub-string within a string.
# Below code finds the position of second occurrence of "xyz"
string = "xyz is equal to xyz"
firstSubPos=string.find("xyz") # get the position of first substring "xyz"
secondSubPos=string.find("xyz", firstSubPos+1) # get the position of second occurence of substring "xyz"
print "position of second occurence of substring \"xyz\" is " + str(secondSubPos) # print the position
Note: Above code works in both Python 2 and Python 3 Output:
This Python code helps you to to replace a string between two delimiters or characters delete/remove string between two characters or delimiters Python code to replace string between two delimiters
# This macro replaces nivas in below string with silveri
string = "sri[nivas]"
firstDelPos=string.find("[") # get the position of [
secondDelPos=string.find("]") # get the position of ]
stringAfterReplace = string.replace(string[firstDelPos+1:secondDelPos], "silveri") # replace the string between two delimiters
print stringAfterReplace # print the string after sub string between dels is replaced
Python code to delete/remove string between two characters/delimiters Replace 5th line of above code with below one
stringAfterReplace = string.replace(string[firstDelPos+1:secondDelPos], "") # remove the string between two delimiters
Note: This code works in both […]
Simple python script to extract sub string between two delimiters of a string. Examples of delimiters are brackets, parentheses, braces, single or double quotes etc. You can also customize this code to extract the string between two special characters or two sub strings. Comments on each line of code explains you to easily understand the code. Note: […]
VBA macro to find duplicates in excel sheet. This macro finds the duplicates in user selected range and highlights them in light red color. VBA code to find and highlight duplicates
Selection.FormatConditions(1).DupeUnique = xlDuplicate
.Color = -16383844
.TintAndShade = 0
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
Selection.FormatConditions(1).StopIfTrue = False
Add above code to your excel workbook How to use this macro Select the range (column/row/columns and rows…) in which you want to […]
VBA macro to turn text URLs to clickable links in excel spreadsheet. This macro Checks whether cell has text URL or not If the cell contains text URL, then it turns it into clickable URL Moves to cell in the next row Repeats the steps from 1 to 3 until it reaches an empty cell […]
Excel VBA macro to extract file name from file path. This macro extracts the string (file name) which is between dot (.) and backslash(\) delimiters (from right side).
' This macro shows you how to extract filename from filepath
' It extracts the filename which is between delimiters dot and backslash
filePath = "C:\Users\Desktop\files\file1.html"
firstDelPos = InStrRev(filePath, ".")
secondDelPos = InStrRev(filePath, "\")
Filename = Mid(filePath, secondDelPos + 1, firstDelPos - secondDelPos - 1)
Excel VBA macro to delete empty columns. Just run this macro, enter number of columns you want to check and the macro checks (starting from first column) and deletes all empty columns within the selected number of columns. In the macro, you can also find VBA syntax to delete empty row and to check whether a […]