Home Web Front-end JS Tutorial JavaScript string replacement and string splitting sample code_javascript skills

JavaScript string replacement and string splitting sample code_javascript skills

May 16, 2016 pm 05:09 PM
String splitting String replacement

JS (JavaScript) string replacement function (a bit like PHP's preg_replace)

str.replace('xxx', 'yyyy'); Replace the first
str.replace(/xxx/g, 'yyyy'); Replace all

string splitting (similar to PHP's splitting function)

Copy code Code As follows:

var test = 'a-b-c-d';
test.split('-');
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to replace the enter key in php How to replace the enter key in php Mar 23, 2023 am 11:12 AM

In PHP program development, sometimes text content needs to be processed, including replacing the Enter key. Below we will briefly introduce how to replace the Enter key in PHP.

How to replace a string starting with something with php regular expression How to replace a string starting with something with php regular expression Mar 24, 2023 pm 02:57 PM

PHP regular expressions are a powerful tool for text processing and conversion. It can effectively manage text information by parsing text content and replacing or intercepting it according to specific patterns. Among them, a common application of regular expressions is to replace strings starting with specific characters. We will explain this as follows

How to use the split() function in Python 3.x to split a string according to the specified delimiter How to use the split() function in Python 3.x to split a string according to the specified delimiter Jul 31, 2023 pm 08:33 PM

Python is a popular programming language that provides many built-in functions to handle strings. One of the commonly used functions is the split() function, which can split a string into multiple substrings according to the specified delimiter. This article will introduce how to use the split() function in Python3.x. In Python, the split() function is a built-in function of the string class. Its basic syntax is as follows: string.split(separator,maxsplit)

How to replace special characters in string using regular expression in PHP How to replace special characters in string using regular expression in PHP Jun 24, 2023 am 10:46 AM

With the continuous development of the Internet, PHP's application scenarios are becoming more and more extensive. In PHP development, sometimes you need to replace special characters in a string. In this case, you can use regular expressions for replacement. This article will introduce how to use regular expressions to replace special characters in strings in PHP. First, learn the basics of regular expressions. Regular expressions are a language used to describe patterns in some strings. Regular expressions include some special characters, such as ., *, +, ?, etc. These special characters have special meanings. in PH

How to replace string from left in php How to replace string from left in php Mar 23, 2023 pm 04:53 PM

PHP is a widely used scripting language that can be used to develop various web applications and websites. In these applications, strings are an integral part. In many cases, we need to perform operations such as replacing, splitting or intercepting strings. This article will explain how to replace a string from the left in PHP.

preg_replace() function in PHP: How to replace string using regular expression preg_replace() function in PHP: How to replace string using regular expression Nov 03, 2023 am 09:09 AM

preg_replace() function in PHP: How to replace a string using regular expressions, specific code examples are needed In PHP, the preg_replace() function is a very powerful and flexible function that allows us to search and replace characters using regular expressions string. Whether it is to remove specific characters from a string or replace text in a specific format, the preg_replace() function can help us achieve it easily. First, let's take a look at preg_replace()

How to use explode function to split string in PHP How to use explode function to split string in PHP Jun 26, 2023 pm 12:03 PM

In the PHP language, there are many basic functions that can help us process strings quickly and efficiently. Among them, the explode function is a very practical string splitting function. It can split a string into arrays according to the specified delimiter, and then perform more flexible string operations. In this article, we will introduce how to use the explode function to split strings in PHP. 1. The format of the explode function. The format of the explode function in the PHP language is as follows: explode(separa

How to replace the 11 digits after the colon in php How to replace the 11 digits after the colon in php Mar 21, 2023 pm 04:32 PM

Replacing strings is one of the most basic operations in PHP. The replacement function is crucial in data processing and string operations, and can improve program execution efficiency and performance. There are many functions for replacing strings in PHP, such as: substr_replace, str_replace, preg_replace and so on. But for specific string replacements, special replacement rules may need to be used. In this article, we will learn how to replace the 11 digits after the colon.

See all articles