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

推荐订阅源

N
News | PayPal Newsroom
Security Archives - TechRepublic
Security Archives - TechRepublic
Hacker News: Ask HN
Hacker News: Ask HN
H
Hacker News: Front Page
Apple Machine Learning Research
Apple Machine Learning Research
TaoSecurity Blog
TaoSecurity Blog
Help Net Security
Help Net Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
V2EX
Hugging Face - Blog
Hugging Face - Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
人人都是产品经理
人人都是产品经理
博客园 - 三生石上(FineUI控件)
Security Latest
Security Latest
Cloudbric
Cloudbric
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Know Your Adversary
Know Your Adversary
A
Arctic Wolf
L
LangChain Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
The GitHub Blog
The GitHub Blog
P
Proofpoint News Feed
W
WeLiveSecurity
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
M
MIT News - Artificial intelligence
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
小众软件
小众软件
NISL@THU
NISL@THU
云风的 BLOG
云风的 BLOG
P
Privacy & Cybersecurity Law Blog
S
Security @ Cisco Blogs
博客园 - 【当耐特】
I
InfoQ
Vercel News
Vercel News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Proofpoint News Feed
O
OpenAI News
Google DeepMind News
Google DeepMind News
N
News and Events Feed by Topic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
K
Kaspersky official blog
T
Threat Research - Cisco Blogs
量子位
宝玉的分享
宝玉的分享

博客园 - 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       }