Posts

Showing posts with the label String

Javascript Code to Replace a Word in a String

Image
This code will Replace a Word in a String using Javascript Javascript <!DOCTYPE html> <html> <head> <title>JavaScript Replace a Word in a String</title> </head> <body> <p id="myText">My favorite color is red</p> <button type="button" onclick="strReplace();">Replace</button> </body> <script> function strReplace(){ var myStr = 'My favorite color is red'; var newStr = myStr.replace(/red/g, "purple"); document.getElementById("myText").innerHTML = newStr;} </script> </html> Click here to run this code Share with Friends                 More Free Code Examples: Javascript Substitution Cipher Javascript Easy Battleship Game Hello World in 10 Programming Languages Try these Fun Games by Bobbie: Travel Blast Game New York Play ...

Python Word Repeater

Image
This code will take a string you enter and repeat it for the number of times you specify using Python.      * Featured code submitted and Created by  Facu . Python def repeater(word, cant):  for i in range(cant):   print(word) try:  a = input()  b = int(input())  repeater(a, b) except (ValueError):  print("An error ocurred:")  print("\nThe second value must be a whole number!") except (EOFError):  print("An error ocurred:")  print("\nYou must enter a number in the second line!") Click here to try this code More Free Code Examples: Python Code to Reverse a String Hello World in 10 Programming Languages 8 Codes to Find Versions

C++ String Rotation

Image
This program accepts a string argument and returns an array of strings, which are shifted versions of the argument string. * Featured post submitted and created by  Padmanabhan .  C++ #include <iostream> using namespace std; void StringRotator(string s, int len); int main() {     string s;          //Getting Input              cin>>s;     if(s. length()!=0)     {         cout<<"[";         StringRotator(s,s.length());         cout<<"]";     }     else         cout<<"Sorry! No input is given";     return 0; } void StringRotator(string s,int len) {         static int i=0;     cout<<"\"";     for(int j=i;j<...

Java Code to Reverse a String

Image
Reverse a String using Java Java public class Reverse {  public static void main(String[] args) {  String str = "Reverse this string";  String reversed = reverseString(str); System.out.println("The reversed string is: " + reversed); }  public static String  reverseString(String str) {  if (str.isEmpty())  return str;  return reverseString(str.substring(1)) + str.charAt(0); } }   Click here to see this code run More Free Code Examples: Hello World in 10 Programming Languages Java Odd or Even Java Current Time and Date Program

C++ Code to Reverse a String

Image
Reverse a String using C++ * Featured Code Example Created and submitted by  Nitrocell  via Sololearn. C++ #include <iostream> #include <string> #include <algorithm> using namespace std; void ReverseSystem() {     cout << "Type what you want to reverse: " << endl;     string tool;     cin >> tool;     reverse(tool.begin(), tool.end());     cout << "Reverse:\n\n" << tool << endl; } int main(void) {     ReverseSystem();            return 0; } Click here to run this code More Free Code Examples: Python Code to Reverse a String C++ Guess the Number C++ Odd or Even

Python Code to Reverse a String

Image
Reverse a String using Python * Featured Code Example Created and submitted by  Nitrocell  via Sololearn. Python tool = input() print("===============Result===============\n\n") print("Normal: " + tool + "\n") print("Reverse: " + tool[::-1]) Click here to run this code More Free Code Examples: C++- Code to Reverse A String Hello World in 10 Programming Languages 8 Codes to Find Versions