当前位置:网站首页>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;
}
边栏推荐
- 设置Canvas的 overrideSorting不生效
- Truly understand triode beginner level chapter (Classic) "suggestions collection"
- Still using simpledateformat for time formatting? Be careful that the project collapses!
- Url追加参数方法,考虑#、?、$的情况
- 【Unity编辑器扩展实践】、通过代码查找所有预制
- 深度学习又有新坑了!悉尼大学提出全新跨模态任务,用文本指导图像进行抠图...
- [C language] use of nested secondary pointer of structure
- .NET混合开发解决方案24 WebView2对比CefSharp的超强优势
- 【Unity编辑器扩展基础】、GUI
- Self use demo of basic component integration of fluent
猜你喜欢

Leetcode 48. 旋转图像(可以,已解决)

What is the difference between internal oscillator, passive crystal oscillator and active crystal oscillator?

Database Series: is there any way to seamlessly upgrade the business tables of the database

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

洛谷_P1303 A*B Problem_高精度计算

RemoteViews布局和类型限制源码分析

Many benefits of SEO optimization are directly related to traffic

2018 joint examination of nine provinces & Merging of line segment trees

【vi/vim】基本使用及命令汇总

. Net hybrid development solution 24 webview2's superior advantages over cefsharp
随机推荐
深度学习又有新坑了!悉尼大学提出全新跨模态任务,用文本指导图像进行抠图...
Leetcode 705. 设计哈希集合
How to get a generic type
已知两个点和中间一个比例的点,求该点坐标
Why do many people want to change careers as programmers, while some programmers want to change careers as others?
Software test interview classic + 1000 high-frequency real questions, and the hit rate of big companies is 80%
Truly understand triode beginner level chapter (Classic) "suggestions collection"
MapReduce project case 3 - temperature statistics
Necessary for beginners PR 2021 quick start tutorial, PR green screen matting operation method
案例驱动 :从入门到掌握Shell编程详细指南
fatal: unsafe repository (‘/home/anji/gopath/src/gateway‘ is owned by someone else)
Daily practice of C language - day 3: calculate the number of occurrences of sub strings of strings
Difference (one dimension)
Source code analysis of ArrayList
What is data compliance? How to achieve data compliance?
女子高考落榜读专科逆袭买千万别墅,考得不好真的没关系
Map sorting tool class
Open3d manual clipping point cloud
Web3 security serials (3) | in depth disclosure of NFT fishing process and prevention techniques
【Unity编辑器扩展基础】、GUILayout