Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I delete the first word from a line?

Mon 25-Jul-2011

I want to delete the first word "Mon" with javascript jQuery. How can i do this ?

like image 694
prime Avatar asked Jul 29 '11 09:07

prime


People also ask

How do I remove the first word from a cell in Excel?

Remove first character in Excel To delete the first character from a string, you can use either the REPLACE function or a combination of RIGHT and LEN functions. Here, we simply take 1 character from the first position and replace it with an empty string ("").

How do I remove the first word from a string in Python?

Method #1: Using split() Method This task can be performed using the split function which performs a split of words and separates the first word of string with the entire words.

How do I delete certain words in word?

Open the document in Microsoft Word or another word processor. Move the mouse cursor to the beginning of the word you want to delete. Press and hold the left mouse button, then drag the mouse to the right until the entire word is highlighted. Press Backspace or Delete to delete the word.


3 Answers

If you don't want to split the string (faster, less memory consumed), you can use indexOf() with substr():

var original = "Mon 25-Jul-2011";
var result = original.substr(original.indexOf(" ") + 1);
like image 76
Frédéric Hamidi Avatar answered Oct 06 '22 22:10

Frédéric Hamidi


var string = "Mon 25-Jul-2011";
var parts = string.split(' ');
parts.shift(); // parts is modified to remove first word
var result;
if (parts instanceof Array) {
  result = parts.join(' ');
}
else {
  result = parts;
}
// result now contains all but the first word of the string.
like image 28
ChristopheCVB Avatar answered Oct 06 '22 22:10

ChristopheCVB


I wanted to remove first word from each items in Array of strings. I did that using split, slice, join.

var str = "Mon 25-Jul-2011"
var newStr = str.split(' ').slice(1).join(' ')
console.log(str)

Run this code in console you will get the expected string.

like image 45
Rahul Sagore Avatar answered Oct 07 '22 00:10

Rahul Sagore