当前位置:网站首页>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
边栏推荐
- 美国服务器租用和托管服务哪个好?
- 事件队列、微任务与宏任务的理解和面试题
- 项目配置了eslint,编辑器没有关闭eslint功能的情况下,eslint没有生效
- 成长一夏 挑战赛来袭 专属社区福利来袭~免费获得CSDN定制T恤衫
- Buttons to achieve various effects and functions. Reading this article is enough
- Entropy - conditional entropy - joint entropy - mutual information - cross entropy
- Pyth Solana is a bridge connecting reality on the chain
- 在广州的朋友,有机会可以参加下
- FH6908A负极关断同步整流模拟低压降二极管控制IC芯片TSOT23-6超低功耗整流器 1w功耗 <100uA静态 替代MP6908
- Temperature measuring instrument based on STM32 single chip microcomputer
猜你喜欢

6-1漏洞利用-FTP漏洞利用

Force deduction ----- count the string containing the given prefix
![[JetsonNano] [教程] [入门系列] [一] 如何开启VNC共享](/img/f5/3f0f69739caa22809f40cf4b7483fe.png)
[JetsonNano] [教程] [入门系列] [一] 如何开启VNC共享

【UML】UML类图

SSM整合流程(整合配置、功能模块开发、接口测试)

Gateway服务网关

Safe holidays without holidays, VR traffic makes children travel safely | Guangzhou Sinovel viewpoint

假期安全不放假,VR交通让孩子安全出行|广州华锐视点

Abaqus 2022软件安装包和安装教程

漫画 | Oracle 被新时代抛弃了吗?
随机推荐
MQ component (2022.5.16-5.22)
在广州的朋友,有机会可以参加下
ArcGIS no plug-in load (no offset) day map
MySQL数据库查询优化
Code shoe set - mt3435 · assignment - bipartite graph problem - Graphic explanation
科大讯飞活跃竞赛汇总!(12个)
手机炒股开户安全嘛!?
Configure server environment
Advanced skills of testers: a guide to the application of unit test reports
[jetsonnano] [tutorial] [introductory series] [i] how to enable VNC sharing
【DesignMode】单例模式(singleton pattern)
IT外包驻场人员怎么定位自己的痛点?
pycharm有用快捷键
请指教在线开户是什么意思?究竟网上开户是否安全么?
SQL continuous login problem
【DesignMode】工厂模式 (factory pattern)
更智能!AIRIOT加速煤炭行业节能减排升级
Browser window switch activation event visibilitychange
2022年高考都结束了,还有人真觉得程序员下班后不需要学习吗?
ROS advertisement data publishing tips - latch configuration