

字符串转化为数组
source link: https://www.oschina.net/question/3955988_2320732
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

1. 用 java:
public class T {
public static void main(String args[]) {
String data ="7,8,9";
String dat [] = data.split(",");
System.out.println("字符串数组");
for (int i=0; i<dat.length;i++)
System.out.print(dat[i] + " ");
System.out.println("\n整型数组");
int dataI [] = new int[dat.length];
for (int i=0; i<dat.length;i++){
dataI[i] =Integer.parseInt(dat[i]);
System.out.print(dataI[i] + " ");
}
}
}
DOS 输出:
D:\java\test\OS_China>java T
字符串数组
7 8 9
整型数组
7 8 9
D:\java\test\OS_China>
2. 用 js
<html>
<body>
</body>
<script language="javascript" type="text/javascript">
data = '7,8,9';
dat = data.split(',');
s = '';
for( i=0; i<dat.length;i++)
s += dat[i] + ' ';
document.write(s);
</script>
</html>
Recommend
-
41
-
30
-
83
字符串是 Go 语言中最常用的基础数据类型之一,虽然字符串往往都被看做是一个整体,但是实际上字符串是一片连续的内存空间,我们也可以将它理解成一个由字符组成的数组,Go 语言中另外一个与字符串关系非常密切的类型就是字节(Byte)了,...
-
33
上一节的学习中,我们已经结合JAVA 本身,将线性表所包含的顺序表、链表、栈、队列等数据结构通通学习了一番,并且将这些数据结构的一些基本操作。比如 add() remove() pop() 等等...
-
34
Go语言中数组、字符串和切片三者是密切相关的数据结构。这3种数据类型,在底层原始数据有着相同的内存结构,在上层,因为语法的限制而有着不同的行为表现。 Go语言的数据是一种值类型,虽然数组的元素可以被修改,但是数组本身的赋...
-
22
值类型和引用类型区别 值类型:使用变量指向 内存的值 ,内存分配通常在栈中,发生赋值和参数传递时是把这个数据的值(可能多个数据,如数组包括数据域和长度)一起拷贝一份。 引用类型:引用类型数...
-
41
有时我们需要将numpy数组初始化为相同的值,numpy提供了一些方法帮助我们实现这个目的。 1. np.zeros np.zeros返回来一个给定形状和类型的用0填充的数组。 numpy.zeros(shape, dtype=float, order='C')...
-
10
[本文结构] 前些天女神在接入我们的组件时候忽然遇到一个问题,女神青睐自然要积极表现,最终问题顺利解决,今天总结下。先说下结论:一个byte是8位,而16进制是4位,所...
-
7
Array.from Array.from方法主要用于将Array-Like Obj(包括DOM对象document.querySeletorAll(...))和iterable对象转化为数组。和下面说的spread操作符相比,它可以直接将Array...
-
7
V2EX › 程序员 百思不得其解: PHP 怎么把一维数组的键值转化为多维数组的键名
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK