Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

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
Shell :: substring replacement 
Shell :: bash script: replace . with : 
Shell :: adobe connect in ubuntu 
Shell :: git stash apply specific stash 
Shell :: linux command disk speed test 
Shell :: git pull from another user 
Shell :: freebsd add user 
Shell :: Exit bash script if not running as root 
Shell :: zsh to bash mac 
Shell :: ffmpeg from frames to video 
Shell :: beam smp 
Shell :: node-pre-gyp install failed with error: error: command failed: node-pre-gyp install --fallback-to-build 
Shell :: check git settings terminal 
Shell :: tar extract gz 
Shell :: npm install from github branch 
Shell :: join docker swarm 
Shell :: screen recorder for ubuntu 
Shell :: print env variables 
Shell :: how to add project to bitbucket 
Shell :: bash script 
Shell :: install php 8 debian 
Shell :: linux install sass 
Shell :: ubuntu change directory owner 
Shell :: yum install node version 12 
Shell :: nodemon script 
Shell :: how to add gif in github readme 
Shell :: android studio (not installed) flutter ubuntu 
Shell :: how to reboot kali linux with commands 
Shell :: search git -G 
Shell :: powershell foreach 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =