Làm cách nào để viết thường một chuỗi ngoại trừ chữ cái đầu tiên JavaScript?

Vấn đề viết hoa một chuỗi khá phổ biến và đã được thảo luận nhiều lần. Nhưng đôi khi, chúng ta có thể gặp một vấn đề như thế này, trong đó chúng ta cần chuyển đổi ký tự đầu tiên của chuỗi thành chữ thường. Hãy để chúng tôi thảo luận về những cách nhất định trong đó điều này có thể được thực hiện.  

Phương pháp số 1. Sử dụng cắt chuỗi + Lower() Tác vụ này có thể dễ dàng được thực hiện bằng cách sử dụng phương thức Lower để viết thường các ký tự được cung cấp cho nó và cắt có thể được sử dụng để thêm chuỗi còn lại sau ký tự đầu tiên viết thường.  

Python3




# Python3 code to demonstrate working of

# Lowercase first character of String

# Using lower() + string slicing

 

# initializing string

test_strThe original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks0 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks1

 

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks2

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks3The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks4_______0_______5 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks6 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks7The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks8

 

# Using lower() + string slicing

# Lowercase first character of String

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks1The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks0 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks3_______0_______4The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks5The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks6 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks3The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks8The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks9

 

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks0

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks3The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks4_______0_______3 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks6 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks7The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks6

đầu ra. The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks

Thời gian phức tạp. Trên)
Không gian phụ trợ. Trên)

Phương pháp #2. Sử dụng lambda + cắt chuỗi + Lower() Công thức của hàm lambda phải được thêm vào nếu chúng ta cần thực hiện tác vụ xử lý cả giá trị Không có giá trị hoặc chuỗi rỗng và điều này trở nên cần thiết để xử lý các trường hợp cạnh.  

Python3




# Python3 code to demonstrate working of

# Lowercase first character of String

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks9

 

# initializing string

test_strThe original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks0 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks1

 

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks2

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks3The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks4_______0_______5 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks6 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks7The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks8

 

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks9

# Lowercase first character of String

 

 

# Python3 code to demonstrate working of3 # Python3 code to demonstrate working of4# Python3 code to demonstrate working of5 # Python3 code to demonstrate working of6The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks8The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks5_______0_______6

 

 

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks3The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks8The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks9# Lowercase first character of String3 test_str# Lowercase first character of String5 # Lowercase first character of String6

 

 

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks0

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks3The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks4_______0_______3 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks6 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks7# Using lower() + string slicing3

đầu ra. The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks

Thời gian phức tạp. Trên)
Không gian phụ trợ. Trên)

Phương pháp #3. Sử dụng phương thức thay thế () mà không cần cắt

Python3




# Python3 code to demonstrate working of

# Lowercase first character of String

 

# initializing string

test_strThe original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks0 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks1

 

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks2

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks3The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks4_______0_______5 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks6 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks7The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks8

 

test_strThe original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks0_______139_______9The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks4test_str1The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks4test_str3The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks8_______140_______5

 

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks0

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks3The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks4_______0_______3 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks6 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks7The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks8

Đầu raThe original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks

Thời gian phức tạp. Trên)
Không gian phụ trợ. Trên)

Phương pháp #4. Sử dụng phương thức cắt lát và chỉ mục ()

Python3




# Python3 code to demonstrate working of

# Lowercase first character of String

 

# initializing string

test_strThe original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks0 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks1

 

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks2

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks3The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks4_______0_______5 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks6 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks7The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks8

 

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks16_______0_______0The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks18

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks19_______0_______0The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks21

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks1The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks0The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks24_______0_______4The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks26The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks6The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks3The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks8_______0_______9

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks0

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks3The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks4_______0_______3 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks6 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks7The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks6

Đầu raThe original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks

Thời gian phức tạp. Trên)
Không gian phụ trợ. Trên)

Phương pháp #5. Sử dụng các hàm ord(),chr()

Python3




# Python3 code to demonstrate working of

# Lowercase first character of String

 

# initializing string

test_strThe original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks0 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks1

 

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks2

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks3The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks4_______0_______5 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks6 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks7The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks8

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks51The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks0 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks53

# Lowercase first character of String3The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks4The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks56The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks57The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks4The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks59The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks0 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks56The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks4The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks63The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks64

The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks65The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks51The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks0 The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks68The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks4The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks56The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks57The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks4The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks73The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks6The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks75test_str5

Làm cách nào để thay đổi tất cả chữ hoa thành chữ thường trừ chữ cái đầu tiên trong JavaScript?

Phương thức toLowerCase chuyển đổi một chuỗi thành chữ thường . Phương thức toLowerCase() không nhận bất kỳ tham số nào. Các chuỗi trong JavaScript là bất biến. Phương thức toLowerCase() chuyển đổi chuỗi được chỉ định thành một chuỗi mới chỉ bao gồm các chữ cái viết thường và trả về giá trị đó.

Làm cách nào để tạo một chuỗi chữ thường trong JavaScript?

Phương thức toLowerCase() trả về giá trị của chuỗi được chuyển thành chữ thường. toLowerCase() không ảnh hưởng đến giá trị của chính chuỗi str.

Làm cách nào để viết hoa chữ cái đầu tiên và viết hoa phần còn lại nhỏ trong JavaScript?

Để viết hoa ký tự đầu tiên của chuỗi, chúng ta có thể dùng hàm charAt() để tách ký tự đầu tiên rồi dùng hàm toUpperCase() để viết hoa ký tự đầu tiên. Now, we would get the remaining characters of the string using the slice() function.

Làm cách nào để kiểm tra xem chữ cái đầu tiên có phải là chữ hoa JavaScript không?

toUpperCase() . Ghi chú. chuỗi. charAt(index) được ưu tiên hơn string[index] (ký hiệu dấu ngoặc).

Chủ đề