Author: Arpit Mandliya
- 08 December
Format Number to 2 Decimal Places in PHP
Using the round() function To format a number to 2 decimal places in PHP, you can use the round() function and pass the number and 2 as arguments to the round() function. Here is an example of how to use the round() function to format a number to 2 decimal places: [crayon-676d62f60adfb688061445/] Output [crayon-676d62f60ae01310093015/] round() […]
- 08 December
Check if Array is Empty in PHP
Use empty() function To check if an array is empty in PHP, you can use the empty() function. This function accepts an array as its argument, and it returns true if the array is empty and false if the array is not empty. Here is an example of how to use the empty() function to […]
- 08 December
Add Property to Object in PowerShell
Using Add-Member cmdlet The Add-Member cmdlet allows you to add members (properties and methods) to an object in PowerShell. To add property to a PowerShell object: Pipe an object to the Add-Member cmdlet followed by the property to add [crayon-676d62f60b9f2744221076/] In the first command, Get-Item C:\test gets the DirectoryInfo object which is saved in a […]
- 08 December
Find Character in String in Python
Using find() Method To find the character in a string in Python: Use the find() method to find the index of the first occurrence of the supplied character in the input String. Use an if statement to check if the returned index is not -1; if so, print that index; otherwise, print an error. [crayon-676d62f60badd259881419/] […]
- 07 December
Get List of Months Between Two Dates in Python
Use pandas.period_range() Method To get the list of months between two specified dates in Python: Use pandas’s period_range() to get list of months between start date and end date with freq='M'. Use list comprehension to iterate over list of months. For each month, use strftime() method to convert it in appropriate format. [crayon-676d62f60c7d3409861332/] The execution […]
- 06 December
Run Batch File from PowerShell
In Windows PowerShell, we can run batch files in multiple ways. Running the batch file by specifying the absolute or relative path using the ampersand (&) operator: [crayon-676d62f60c8f9583615131/] Running the batch file by using the Invoke-Expression cmdlet. This command works similarly with the ampersand operator (&), but we write it in PowerShell flavor. [crayon-676d62f60c8fc980986718/] Running […]
- 05 December
Remove Substring from String in Python
Use replace() Method To eliminate a substring from string in Python: Define and initiate my_string. Declare substring to remove it from my_string. Use replace() method to remove substring from string. e.g. my_string = my_string.replace(substring, "") [crayon-676d62f60ca8e949167365/] The code above will print the following output on the console: [crayon-676d62f60ca92674336776/] We tried removing the substring from my_string. […]
- 05 December
Replace Space with Underscore in PHP
Using str_replace() Method Use the str_replace() function to replace with underscore in PHP, for example: str_replace(" " , "_", $str). str_replaces() returns new String with old character space( ) replaced by underscore(_) [crayon-676d62f60cc16019067118/] [crayon-676d62f60cc1a530400889/] We used str_replace() to replace space with underscore in PHP. str_replace() replaces all instances of search string with replacement String. It […]
- 04 December
Get Driver Versions in PowerShell
Using win32_PnpSignedDriver class of the WMI object To get driver versions in PowerShell, use win32_PnpSignedDriver class of the WMI object. [crayon-676d62f60ccd2565159659/] After running the command, your PowerShell should give you an output something like this: Note how the columns are arranged as Device Name, Device Version, and Description. If you are to write the command […]