当前位置:网站首页>Some tips on string conversion
Some tips on string conversion
2022-06-28 12:20:00 【Unique_ eight hundred and forty-nine million nine hundred and n】
In the development process, we usually encounter the need to cut strings , You can use some special symbols as separators for strings , such as +、&、| etc. , Then use these symbols to cut the string , Get an array of strings , for example :
//string str= "5+30";
public string[] Str2StrArray(string str, char symbol)
{
if (string.IsNullOrEmpty(str))
{
return new string[0];
}
return str.Split(symbol);
}Maybe what you want is Int Array , You can also convert a string to Int, Then get Int Array , for example :
//string str= "5+30";
public int[] Str2IntArray(string str, char symbol)
{
if (string.IsNullOrEmpty(str))
{
return new int[0];
}
string[] strArray = str.Split(symbol);
if (strArray.Length < 1)
{
return new int[0];
}
int[] value = new int[strArray.Length];
for (int i = 0; i < strArray.Length; i++)
{
value[i] = Convert.ToInt32(strArray[i]);
}
return value;
}If one-dimensional arrays can not meet your needs , You can add two more split characters , Convert split data to Crossed array , for example :
public int[][] GetIntArray()
{
string value = "5+30|10+40|15+45|20+50";
string[] _strArry = Str2StrArray(value, '|');
int[][] _temp = new int[_strArry.Length][];
for (int i = 0; i < _strArry.Length; i++)
{
int[] _intArray = Str2IntArray(_strArry[i], '+');
_temp[i] = _intArray;
}
return _temp;
}
边栏推荐
- 【附源码+代码注释】误差状态卡尔曼滤波(error-state Kalman Filter),扩展卡尔曼滤波,实现GPS+IMU融合,EKF ESKF GPS+IMU
- SEO优化的许多好处是与流量有直接关系
- 建立自己的网站(18)
- Necessary for beginners PR 2021 quick start tutorial, PR green screen matting operation method
- 【C语言】文件读写函数使用
- websocket 1 分钟自动断开连接
- Is there a threshold for opening futures accounts? How to open futures accounts safely on the Internet
- 零基础C语言(一)
- [Beijing University of Aeronautics and Astronautics] information sharing for the first and second examinations of postgraduate entrance examination
- Cohere, a large model company, completed the round B financing of US $125million
猜你喜欢

SEO优化的许多好处是与流量有直接关系

Swin, three degrees! Eth open source VRT: a transformer that refreshes multi domain indicators of video restoration

Why do many people want to change careers as programmers, while some programmers want to change careers as others?

【北京航空航天大学】考研初试复试资料分享

UGUI强制刷新Layout(布局)组件

开源项目维权成功案例: spug 开源运维平台成功维权

【C语言】NextDay问题

【C语言】二叉树的实现及三种遍历

【Unity编辑器扩展基础】、EditorGUILayout (三)
Three ways to implement LRU cache (recommended Collection)
随机推荐
【vi/vim】基本使用及命令汇总
Asynctask experience summary
【编解码】从零开始写H264解码器(1) 总纲
IDEA全局搜索快捷设置
30套JSP网站源代码合集「建议收藏」
SHA256加密工具类
2. single digit statistics
JNI函数的2种书写方式
C语言 sprintf函数使用详解
NFT数字藏品系统开发(3D建模经济模型开发案例)
Difference (one dimension)
MapReduce project case 3 - temperature statistics
MapReduce项目案例1
如何获取泛型的类型
. Net hybrid development solution 24 webview2's superior advantages over cefsharp
Django -- MySQL database reflects the mapping data model to models
AcWing 606. Average 1 (implemented in C language)
Software test interview classic + 1000 high-frequency real questions, and the hit rate of big companies is 80%
Daily practice of C language - day 4: find the sum of all even numbers within 100
零基础C语言(一)