Warning: mysqli_result::fetch_assoc() expects exactly 0 parameters, 1 given in /var/www/powershellpower.com/public_html/page_parts/page.php on line 78

Warning: Use of undefined constant page_id - assumed 'page_id' (this will throw an Error in a future version of PHP) in /var/www/powershellpower.com/public_html/page_parts/page.php on line 92

Warning: Use of undefined constant synopsis - assumed 'synopsis' (this will throw an Error in a future version of PHP) in /var/www/powershellpower.com/public_html/page_parts/page.php on line 93

How to remove the first n number of characters from a string

Several methods of trimming the first few charachters from a string in powershell

5
Warning: mysqli_result::fetch_assoc() expects exactly 0 parameters, 1 given in /var/www/powershellpower.com/public_html/page_parts/page.php on line 156

Warning: Use of undefined constant text - assumed 'text' (this will throw an Error in a future version of PHP) in /var/www/powershellpower.com/public_html/page_parts/page.php on line 185
Method 1

The first method is using the 'substring' command, with this command we can remove characters from the beggining of the string, the number placed within the brackets is the number of characters to be removed.


$test = "we shall remove the first letter"
$test.Substring(1)
result = e shall remove the first letter



Warning: Use of undefined constant text - assumed 'text' (this will throw an Error in a future version of PHP) in /var/www/powershellpower.com/public_html/page_parts/page.php on line 185
Method 2

In this method we are actually replacing the text using the ‘replace' command, when we replace with nothing we get the result of removing the first characters


$test = "we shall remove the first word"
$test.Replace("we ","")
result = shall remove the first word



Warning: Use of undefined constant text - assumed 'text' (this will throw an Error in a future version of PHP) in /var/www/powershellpower.com/public_html/page_parts/page.php on line 185
Method 3

This method will remove a range of the same character from the start of the string, the curious thing about this command is that the first letter has to be declared in the brackets, yet it does not seem to work with any characters beyond the first one, if you have any idea why this is please leave a comment


$test = "wwwwwwe shall remove the first row of w's"
$test.TrimStart("w")
result = e shall remove the first row of w's


Comments

Notice: Undefined variable: commentno in /var/www/powershellpower.com/public_html/page_parts/page.php on line 335
// Collect comments ''
Fatal error: Uncaught Error: Call to a member function fetch_assoc() on bool in /var/www/powershellpower.com/public_html/page_parts/comments.php:9 Stack trace: #0 /var/www/powershellpower.com/public_html/page_parts/page.php(343): include() #1 /var/www/powershellpower.com/public_html/pages/how_to_remove_the_first_n_number_of_characters_from_a_string.php(2): include('/var/www/powers...') #2 {main} thrown in /var/www/powershellpower.com/public_html/page_parts/comments.php on line 9