\\\022a.0\n字符串长度
时间: 2023-12-12 16:36:02 浏览: 80
以下是两个关于字符串长度的例子:
1. 使用Java编写的获取固定长度随机字符串的方法:
```java
/**
* 固定长度的随机字符串
* @param length 长度
* @return 随机串
*/
public static String getRandStringEx(int length){
char[] charList = {'0','1','2','3','4','5','6','7','8','9',
'a','b','c','d','e','f','g','h','i','j',
'k',l','m','n','o','p','q','r','s','t',
'u','v','w','x','y','z','A','B','C','D',
'E','F','G','H','I','J','K','L','M','N',
'O',P','Q','R','S','T','U','V','W','X',
'Y','Z'};
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
sb.append(charList[(int) (Math.random() * charList.length)]);
}
return sb.toString();
}
```
2. 使用C语言编写的获取字符串长度的方法:
```c
#include <stdio.h>
#include <string.h>
int main(void) {
char str[] = "\022a.0\n";
int length = strlen(str);
printf("字符串长度为:%d\n", length); // 输出:字符串长度为:6
return 0;
}
```
阅读全文