Powershell替代和截断——replace and substring
一:截取一个字符串的尾部,替代字符串中的特定字符或替代字符串中特定位置的特定字符
$a="W.endy.chen.SHAO"
$b=$a.Substring(0,$a.Length-5) -replace "\.","_"
$c=$a.Substring(0,$a.Length-5).Replace(".","_")
$d=($a.substring(0,$a.Length-5)) -replace "\.(?!.*\.)","_"
#只替换最后一个.为_,其他.保持不变
echo $a,$b,$c,$d
结果:
W.endy.chen.SHAO
W_endy_chen
W_endy_chen
W.endy_chen
Powershell替代和截断——replace and substring的更多相关文章
- replace(),indexOf(),substring(),split(),join(),——各种小知识点
1.replace ———— 实现去除指定字符串功能,可以用空字符串代替,也可以去新字符代替已有的字符. var str="123_z.jpg"; str=str.replace( ...
- JAVA insert() 插入字符串 reverse() 颠倒 delete()和deleteCharAt() 删除字符 replace() 替换 substring() 截取子串
insert() 插入字符串 StringBuffer insert(int index,String str) StringBuffer insert(int index,char ch) Stri ...
- LeetCode 1234. Replace the Substring for Balanced String
原题链接在这里:https://leetcode.com/problems/replace-the-substring-for-balanced-string/ 题目: You are given a ...
- 【leetcode】1234. Replace the Substring for Balanced String
题目如下: You are given a string containing only 4 kinds of characters 'Q', 'W', 'E' and 'R'. A string i ...
- 使用PowerShell替代WinDbg在高分辨率笔记本下调试、排错
最近换新的开发笔记本,分辨率较高发现部分应用在High DPI下几乎没法用.比较纠结的就是WinDbg,频繁切换分辨率.显示文字大小影响工作节奏.幸好PowerShell在High DPI下效果不错. ...
- 重构第31天 使用多态替代条件语句( Replace conditional with Polymorphism)
理解:本文中的”使用多态代替条件判断”是指如果你需要检查对象的类型或者根据类型执行一些操作时,一种很好的办法就是将算法封装到类中,并利用多态性进行抽象调用. 详解:本文展示了面向对象编程的基础之一“多 ...
- 【转】PowerShell入门(二):PowerShell是Cmd命令行的加强版吗?
转至:http://www.cnblogs.com/ceachy/archive/2013/01/31/PowerShell_vs_Cmd.html PowerShell是命令行的加强版吗?Power ...
- Js 替代
替代全部:.replace(/#/g,"/") 替代第一个:.replace("#","/") var regS = new RegE ...
- Java中substring函数的简单应用
1.删掉一个字符串中的某个字符 /* * 使用Java 中的 substring()函数删掉字符串中的某个字符 * deleteAssignChar函数的参数说明: * str:被操作的字符串 * o ...
随机推荐
- [Objective C]super dealloc 调用时机
转自:http://dcm19872007.blog.163.com/blog/static/86519374201311953739818/ objective-c 语言中最头疼的事就是内存释放,申 ...
- 批处理-IF详解
在CMD使用IF /?打开IF的系统帮助(自己看我就不全部列出来了),我们会发现IF有3种基本的用法! IF [NOT] ERRORLEVEL number command IF [NOT] stri ...
- python学习笔记(10)--爬虫下载煎蛋图片
说明: 1. 有很多细节需要注意! 2. str是保留字,不要作为变量名 3. 保存为txt报错,encoding=utf-8 4. 403错误,添加headers的方法 5. 正则match只能从开 ...
- lua错误收集
这里放一些我遇到的lua错误,希望大家分享一些错误给我,统一放在这里. 1.lua表的引用传值 上面的代码运行后会发现t2[2],t2[3]表里的内容也被删除了,实际上它们 与t2[1]表里的内容都是 ...
- C - The C Answer (2nd Edition) - Exercise 1-2
/* Experiment to find out what happens when printf's argument string contains \c, where c is some ch ...
- C++:成员函数实现在类定义中与在类定义外的区别
//a.cpp class A{ public: int fun(int x){ ); } }; void tt() { } //b.cpp class A{ public: int fun(int ...
- QTableWidget与QTableView的区别
QTableWidget继承自QTableView.QSqlTableModel能与QTableView绑定,但不能于QTableWidget绑定 QSqlTableModel *model = ne ...
- Android——onCreate( )方法详解(转)
android开发之onCreate( )方法详解 onCreate( )方法是android应用程序中最常见的方法之一,那么,我们在使用onCreate()方法的时候应该注意哪些问题呢? 先看看Go ...
- Istio流量管理实现机制深度解析
https://zhaohuabing.com/post/2018-09-25-istio-traffic-management-impl-intro/TOC 前言 Pilot高层架构 统一的服务模型 ...
- Windows 安装、重装MySQL时,报错:could not start the service mysql
原因: 卸载mysql时并没有完全删除相关文件和服务,需要手动清除. 解决方法: 首先,在管理工具->服务里面将MySQL的服务给停止(有的是没有安装成功,有这个服务,但是已经停止了的). 然后 ...