当前位置:网站首页>c语言数组截取,C# 字符串按数组截取方法(C/S)
c语言数组截取,C# 字符串按数组截取方法(C/S)
2022-06-30 19:00:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
private void button1_Click(object sender, EventArgs e) {
string[] aa = this.GetYouhouComment(“aaa王ああああああddddd”, 4);
}
/// 元文字列
/// 桁数
/// 取得する結果
private string[] GetYouhouComment(string PValue, int PLenth) {
string[] result = new string[5];
string shiteiResult = PValue.Replace(“,”, string.Empty);
// 文字列へ内容を転換処理を行う。
int byteCount = Encoding.GetEncoding(932).GetByteCount(shiteiResult);
int j = 0;
// 指定する桁数>=文字列の桁数の場合
if (PLenth >= byteCount) {
shiteiResult = string.Empty.PadRight(PLenth – byteCount) + shiteiResult;
result[j] = shiteiResult;
// 以外の場合
} else {
string strValue = string.Empty;
string strCompare = string.Empty;
// 指定する桁数な文字列を取得する。
for (int i = 0; i < shiteiResult.Length; i++) {
strCompare = shiteiResult.Substring(i, 1);
// GetEncodingメソッドの引数’932’がSJISを示します。
if (Encoding.GetEncoding(932).GetByteCount(strValue) +
Encoding.GetEncoding(932).GetByteCount(strCompare) > PLenth) {
if (j < 5) {
result[j] = strValue;
strValue = strCompare;
j = j + 1;
} else {
break;
}
} else {
strValue = strValue + shiteiResult.Substring(i, 1);
if (i == shiteiResult.Length – 1) {
result[j] = strValue;
}
}
}
}
return result; }
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/132229.html原文链接:https://javaforall.cn
边栏推荐
- Pyth-Solana链上联通现实的桥梁
- Browser window switch activation event visibilitychange
- Friends in Guangzhou can join us if they have the opportunity
- How to use the low code platform of the Internet of things for service management?
- Promise从认识到使用
- 线上线下双结合,VR全景是家具线上转型好方法!
- MQ component (2022.5.16-5.22)
- 一文详解|Go 分布式链路追踪实现原理
- ArcGIS no plug-in load (no offset) day map
- MySQL数据库查询优化
猜你喜欢
随机推荐
[multithreading] use the thread pool to implement a simple thread pool
Abaqus 2022软件安装包和安装教程
Understanding of event queue, micro task and macro task and interview questions
为什么越来越多的人选择云渲染?
Promise from recognition to use
mysql中union和union all的区别
Kubernetes为什么会赢,容器圈的风云变幻!
Code shoe set - mt3435 · assignment - bipartite graph problem - Graphic explanation
配置服务器环境
[solved] how does Tiktok cancel paying attention to the cancelled account
Sqlserver SQL Server Management Studio and transact SQL create accounts and create read-only users to access the specified database
Introduction to Po mode "suggestions collection"
Kalman filter -- Derivation from Gaussian fusion
ros advertise 发布数据小技巧--latch配置
程序员女友给我做了一个疲劳驾驶检测
笔记软件的历史、选择策略以及深度评测
Word -- a solution for word to encounter errors when trying to open a file
【已解决】抖音如何取消关注已注销的账户
A detailed explanation of the implementation principle of go Distributed Link Tracking
设计电商秒杀系统