Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

replace first occurence of substring

#To replace the first occurrence of a pattern with a given string,
#use ${parameter/pattern/string}:

#!/bin/bash
firstString="I love Suzi and Marry"
secondString="Sara"
echo "${firstString/Suzi/$secondString}"    

# prints 'I love Sara and Marry'

#To replace all occurrences, use ${parameter//pattern/string}:

message='The secret code is 12345'
echo "${message//[0-9]/X}"           
# prints 'The secret code is XXXXX'


#(This is documented in the Bash Reference Manual, §3.5.3 "Shell Parameter Expansion".)
Comment

java replace first occurrence of substring

String payment = "10.20.30.40";
payment = payment.replaceFirst("[.]", ",");  // Replace the first dot (.) with coma (,)
System.out.println(payment);  // 10,20.30.40
Comment

PREVIOUS NEXT
Code Example
Java :: numbers of digits java 
Java :: java nested loop 
Java :: java median of list 
Java :: java for each loop 
Java :: java get number out of string 
Java :: char to unicode java 
Java :: Send image file to server useing Retrofit 
Java :: java create empty arraylist 
Java :: how to make a loop in java 
Java :: java convert date to localdate 
Java :: java append file 
Java :: arraylist to array java 
Java :: runtime intalize array in java 
Java :: passing array by reference java 
Java :: fragment to fragment 
Java :: hello world! java 
Java :: 123 movies 
Java :: how to format a double in java to 2 decimal places 
Java :: java class name to string 
Java :: set textview text android java 
Java :: java checking the amount of duplicates in array 
Java :: find java_home path in cmd 
Java :: number format java 
Java :: Java char data type 
Java :: Finding the Sum of an Array in Java 
Java :: how to add string to array in java 
Java :: mouselistener in java 
Java :: java print default options 
Java :: read wss endpoint java 
Java :: java date and time 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =