惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
F
Full Disclosure
C
Check Point Blog
雷峰网
雷峰网
WordPress大学
WordPress大学
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
博客园 - Franky
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
Martin Fowler
Martin Fowler
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
MyScale Blog
MyScale Blog
M
MIT News - Artificial intelligence
IT之家
IT之家
博客园 - 聂微东
L
LangChain Blog
博客园 - 司徒正美
博客园_首页
云风的 BLOG
云风的 BLOG
L
LINUX DO - 最新话题
Jina AI
Jina AI
Latest news
Latest news
L
LINUX DO - 热门话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
B
Blog RSS Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Palo Alto Networks Blog
T
Tor Project blog
Microsoft Azure Blog
Microsoft Azure Blog
T
Tenable Blog
爱范儿
爱范儿
T
The Exploit Database - CXSecurity.com
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
S
Securelist
F
Fortinet All Blogs
AWS News Blog
AWS News Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Security Latest
Security Latest
J
Java Code Geeks
T
Threatpost
The Register - Security
The Register - Security
G
Google Developers Blog
Know Your Adversary
Know Your Adversary
T
Tailwind CSS Blog

博客园 - sunwugang

026.数据库Sqlserver解决远程连接问题 C# SqlSuger C# DataTableToList 批处理自动删除指定文件夹中的文件夹以及文件 C# 开机自启动批处理bat文件 C# 将exe可执行程序设置为开机自启动 025.数据库下载&win10安装注意事项 024 数据库信息查询 + 连接串配置 C# Json操作 C# TextBox 新增文本并定位光标 C# base64转pdf + 上传至指定url C# 猜字谜 C# 闲来笔记 Vue学习笔记72--element ui Vue学习笔记71--histroy模式+hash模式 Vue学习笔记70--全局前置-路由守卫 + 后置路由守卫 + 独享守卫 + 组件内守卫 Vue学习笔记69--activated + deactivated Vue学习笔记68--缓存路由组件 Vue学习笔记67--编程式路由导航
StringHelper--字符串左右添加指定字符
sunwugang · 2024-04-12 · via 博客园 - sunwugang

StringHelper--字符串左右添加指定字符

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Configuration;
 4 using System.Linq;
 5 using System.Text;
 6 using System.Threading.Tasks;
 7 
 8 namespace HRMessageApp.Helper
 9 {
10     public class StringHelper
11     {
12         //定义一个用于保存静态变量的实例
13         private static StringHelper instance = null;
14         //定义一个保证线程同步的标识
15         private static readonly object locker = new object();
16         //构造函数为私有,使外界不能创建该类的实例
17         private StringHelper() { }
18         public static StringHelper Instance
19         {
20             get
21             {
22                 if (instance == null)
23                 {
24                     lock (locker)
25                     {
26                         if (instance == null) instance = new StringHelper();
27                     }
28                 }
29                 return instance;
30             }
31         }
32 
33         public string StrAppendChar(string str, char pChar = '"')
34         {
35             StringBuilder buf = new StringBuilder();
36             buf.Append(pChar);
37             buf.Append(str);
38             buf.Append(pChar);
39             return buf.ToString();
40         }
41 
42 
43         public string StrPadRightAndLeft(string str, char pChar = '"')
44         {
45             string one = str.PadLeft(str.Length + 1, pChar); ;
46             string two = one.PadRight(one.Length + 1, pChar);
47 
48             return two;
49         }
50 
51         public string StrLeftRightAppendChar(string str, char pChar = '"')
52         {
53             //string one = str.Replace(str.Substring(0, 1), pChar + str.Substring(0, 1));
54             string one = str.Replace(str, pChar + str);
55             string two = one.Replace(one, one + pChar);
56 
57             return two;
58         }
59 
60         public string StrLeftRightInsertChar(string str, char pChar='"')
61         {
62             string one = str.Insert(0, pChar.ToString()); //Insert() 在字串中指定索引位插入指定字符
63             string two = one.Insert(one.Length, pChar.ToString());
64 
65             return two;
66         }
67 
68         public string StrLeftRightPlusChar(string str, char pChar = '"')
69         {
70             return pChar + str + pChar;
71         }
72 
73         public string StrLeftRightAddChar(string str, char pChar = '"')
74         {
75             //string result = $"{pChar}{str}{pChar}";
76             return $"{pChar}{str}{pChar}"; 
77         }
78 
79 
80     }
81 }

补充方法:

 1       private static string MergeString(params string[] strs)
 2       {
 3           //string message = MergeString("\"", "abc", "\"");
 4           string result = string.Empty;
 5           foreach (string str in strs)
 6           {
 7               result = result + str;
 8           }
 9           return result;
10       }