JavaScript - How Do I Remove The First Character Of A String?
So say if my string was..
Code: a = "Hello"; alert(a); How do I get it to say; Code: alert("ello"); So how do I take off the 'H' in this example.. Similar TutorialsHello, I'm trying to remove one of the $ signs from this string below. I've gotten as far as removing them both. I'm having trouble removing one of them. Can someone help? Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> <script> $(document).ready(function(){ /*v = $("span.name").html().replace(/,/g,''); $("span.name").html(v);*/ v = $("div.test td").html().replace(/\$/g,''); $("div.test td").html(v); }); </script> <!-- <span class="name"><span class="gost">Yahoo</span>, </span>--> <div class="test"> <table><tr> <td>3-7 Business Days $$0</td></tr></table> </div> </body> </html> Suppose I have the string 'ello'. I want to insert the letter 'h' in the beginning of that string. How do I do that without using a special function? I can only use the functions charAt and indexOf - anyone has any idea? Hi all I am fairly used to programming, but not javascript, and I'm struggling a bit here... I am building a string inside a variable prior to printing it on screen as follows : Code: myclock += hours+':'+minutes; where "hours" and "minutes" are variables initialised elsewhere. How can I add a carriage return or new line character to the end of this line, so that anything else cocatenated to this variable is displayed on the next line. Thanks and have a nice evening. DeeJayBee is there a function in JS to remove a string from some text but without using the replace function? I am removing a specific string from my text using and using the replace function of the match text with a non breaking space but what i really do not want to add anything to my html. The replace is been place in a visual editor box after the user adds text and save the form, this is the code i am using to replace the code, i am using a regular expression to look for <META content="MSHTML 6.00.6000.16890" name="GENERATOR"><LINK title="/iw/ewebeditpro20/ektnormal.css" href="/iw/ewebeditpro20/ektnormal.css" rel="stylesheet"> : // Pass 1 - Removes extra code checks on Regular Expression inside replace function var newstrchanged = strEscaped.replace(/^%26%2365279%3B%20%3CMETA%20content%3D%22MSHTML%20.+.stylesheet%22%3E/g, ''); Is it possible to convert "xyz123456xyz789" into "123456xyz789"? What I'm trying to say is, remove the first occurence of "xyz" from the string, so that all the other occurrences of "xyz" that aren't the first one, remain. Help is appreciated. Thanks, Jazzo First of all, I wanna make my code using (while loop, do while loop, int, double, if, else, else if, Math.random, Scanner-- not string or boolean). -Actually the game goes like, after the user and the computer has has selections it is gonna be displayed and then tell who wins and who does not--I dont know how to do it. - When user presses 4, the the computer tells wins, loses and ties. This happens to me after two tries, wheteher i press 4 or not.(actully its |y/n| in mine and i want to change it to just 4 to quit). -The user is only allowed numbers from 1 to 4, but apparently, i add any number and it works. -My code gos like this: import java.util.Scanner; import java.util.Random; public class boobitty { public static void main (String[] args) { int Computer=0,Player=0,tie=0,compic,pscore; String str="y"; Random generate= new Random(); Scanner scan=new Scanner(System.in); while (str.equals("y")) { compic=generate.nextInt(3)+1; System.out.println ("Enter 1 for Rock, 2 for Paper, and 3 for Scissors"); pscore=scan.nextInt(); if (compic==pscore) { System.out.println("Tie Game"); tie++; } else { switch (pscore) { case 1: { if (compic==2) { System.out.println ("Paper beats Rock"); System.out.println ("Computer wins"); Computer++; } else { System.out.println ("Rock beats Scissors"); System.out.println ("Player wins!"); Player++; } break; } case 2: { if (compic==1) { System.out.println ("Paper beats Rock"); System.out.println ("Player wins!"); Player++; } else { System.out.println ("Scissors beat Paper"); System.out.println ("Computer wins!"); Computer++; } break; } case 3: { if (compic==1) { System.out.println ("Rock beats Scissors"); System.out.println ("Computer wins"); Computer++; } else { System.out.println ("Scissors beat Paper"); System.out.println ("Player wins"); Player++; } break; } default: { System.out.println("Enter 1 2 or 3"); break; } } } Scanner scen = new Scanner (System.in); System.out.println ("Play again? y/n"); str = scen.nextLine(); if(!(str.equals("y"))) { System.out.println ("Scores:"); System.out.println ("Ties= "+tie+" Wins= "+Player+" Losses= "+Computer); } else { System.out.println ("playing again"); } } } } Hey all, I have a simple example below showing how when I pass in the value of the value attribute of option node, and then use if operator to check whether parameter is a string or not, even though it's a string, it converts it to false boolean and triggers the else statement rather than calling a function: Code: <body> <select> <option value="createMsg">Add Message</option> <option value="removeMsg">Remove Message</option> </select> </body> Code: var menu = { handleMenu : function(callback){ if(callback === "string"){ menu[callback](); } else { console.log("Issue occurred") } }, createMsg : function(){ var content = document.createTextNode("Please give additional information."), heading = document.createElement("h1"); heading.appendChild(content); document.body.appendChild(heading); }, removeMsg : function(){ } } document.getElementsByTagName('select')[0].onchange = function(){ menu.handleMenu(this.value)}; callback should be a string so why is it saying otherwise? Thanks for response Specifically i was wondering if anyone had any ideas on how to select the specific character when hovering over a word? I have not been able to find any documentation on this however, there is a demo site i found for a plugin that allows character selection. http://labs.bitmeister.jp/moamoa/demo.html i dont need anything that large and elaborate... Edit I'm pretty wel experinced with jquery, I know it's possible with jquery Hi Im new to javascript and need some help with a project I have, the task I have is: Create a page that can take a bloke of text and out put the following o How many times each letter occurs o How many spaces o How many words o How many times each word occurs o A list of things that are not words or special characters I think maybe use an array but im not sure, like I said im new to this so not too sure on how to do it. I know it would read into a file say a txt file and sort through it this way, possibly using some kind of loop to read through all of the text before sorting it and I know it might use variables. I know how to kind of work through the task I have, but to actually implement the mechanics of the javascript is something that I then struggle with Thanks to all that help. Hi all, I cant get this code to work because I do not know how to include the % character. Any help would be appreciated. My line break isnt working either Cheers, Adrian Code: rightButton.innerHTML = (rightOutcome1Prob+" chance of "+rightOutcome1+"\r\n else "+rightOutcome2); Hello all, I need assistance checking for valid characters in a username/password set up. I have been reading up on form validation but can't find exactly what I am looking for and need help deciphering what's going on. I have a list of accepted characters: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_@" a-z, A-Z, 0-9, dot, dash, underscore, and at. I want to then check an inputed string against that set and if a character is notin the accepted set, to send an alert. Here is what I have gathered so far: a for loop that increments through the values' .length - this is what checks each individual character. Then use of indexOf() can tell me which character is unacceptable. Now is where I am stuck and coming to you. Please help Ok I have a textarea field that is validated by Js, this textarea can and will contain the newline character Code: \n so I validate in JS Code: if(textareaname.value.length < 200) this hten goes through to my php where i also check before I place in to the Database using MYSQL Code: if( strlen($_POST['textareaname']) < 200 ) but my php is giving me a different string length from my javascript. It looks as if Javascript is counting a newline as 1 character and php is treating it as 2. I have checked my slashes, I have used various REgex to check these data amounts. I have also Googled around and there doesnt seem much around. Any ideas? Any suggestions as to how I can make php and javascript treat a newline as the same amount of characters? Thanks in advance. Hi i need a little help on a JavaScript program it ask the user for a keyboard character and a number of rows and columns to look like this RRRRR R___R R___R R___R RRRRR and also this in another program rrrrrr rrrrrr rrrrrr rrrrrr I currently have <html><body> <script type="text/javascript"> // Declare variables and constants var userInputText; // user input to go var numRow; // number of the rows var NumCol; // number of the columns var ES = ""; // empty string userInputText = prompt("Enter a keyboard character",ES); numRow = prompt("Enter the number of rows",ES); NumCol = prompt("Enter the number of columns",ES); //need a nested loop to draw the character box </script> </body> </html> if any one can help me finish this program i would appreciate it Hey Guys, I wanted to prepend a character to menu items when the mouse will hove over them. An example of this is seen on the website of Minivegas, he http://minivegas.net/ When you hover over a menu item at the top a slash appears in front. There seems to happen a couple of things to smoothen out the effect of prepending the character. I was looking for a similarly smooth way of adding a character in front of my menu items. Can anybody help me out on how to do this? I'm also unable to find out exactly how they did it on the Minivegas website. Anybody any ideas? Thanks in advance! Regards, Roy H, I'm trying to create an sms form. but I want the users to be able to monitor the characters and sms number as they type...taking 160 characters to be 1 page. pls I'll need help with coding this form to display characters left in 'ch_count' box and number of pages in the 'pages' box while typing in the 'message' textarea....hope it's clear enough...thanks Code: <p> <textarea name="message" cols="" rows="" id="message"></textarea> </p> <p> <input name="ch_count" type="text" id="ch_count" size="8" /> characters left <input name="pages" type="text" id="pages" size="8" /> pages </p> I have the following code as shown below: Code: <script type="text/javascript"> var a = 12; var b = 35; var c = 56; document.write(a.toString(36).toUpperCase() + "<br>"); document.write(b.toString(36).toUpperCase() + "<br>"); document.write(c.toString(36).toUpperCase() + "<br>"); </script> The problem right now is that for the first 36 number, it always miss the 'prefix 0'. From the code above, it will return the following: Code: C Z 1K My intention was to have all of them display in two character format, as shown below: Code: 0C 0Z 1K May I know how should I do it without having to use if (a < 36) else ... statement? Greetings, I am having trouble finding any examples to help me strip everything up to a certain character (the hypen) in a url. Hypothetical example below, as I only know how to accomplish this using a literal only for one url at a time but I need this for changing urls: Code: <script language="JavaScript"><!-- var temp = new String('http://www.site.com/abc_123_abc_-1379820930'); temp = temp.replace("http://www.site.com/abc_123_abc_-", ''); document.write(temp); //--></script> And I am hoping to be left with the series of numbers on the end. Any help is greatly appreciated. |