在C#编程语言(涵盖C#4.0)(第4版),1.3类型和变量,第9页.
Hooray for byte是一个无符号类型!事实上,在Java中,一个字节被签名(并且没有无符号的等价物),这使得很多无意义的错误容易出错.很可能我们都应该比我们更多地使用uint,请注意:我确信许多开发人员在需要整数类型时默认达到int.框架设计者当然也属于这一类:为什么String.Length应该签名?
当我反编译String.Length ;
/// <summary>
/// Gets the number of characters in the current <see cref="T:System.String"/> object.
/// </summary>
///
/// <returns>
/// The number of characters in the current string.
/// </returns>
/// <filterpriority>1</filterpriority>
[__DynamicallyInvokable]
public int Length { [SecuritySafeCritical, __DynamicallyInvokable, MethodImpl(MethodImplOptions.InternalCall)] get; }
Run Code Online (Sandbox Code Playgroud)
也在MSDN中 ;
Length属性返回此实例中Char对象的数量,而不是Unicode字符数.原因是Unicode字符可能由多个Char表示.
它返回当前字符串中的字符对象数.为什么在已经存在类型的情况下String.Length返回?什么是的点和?Int32UInt32signed-unsigned byteString.Length
我们的讲师解释说这个函数计算字符串的长度......
int strlen_1(const char *str) {
const char *temp = str;
while(*temp != '\0') {
temp++;
}
return temp - str;
}
Run Code Online (Sandbox Code Playgroud)
...会比这个更快地计算...
int strlen_03(const char *str) {
int i;
for (i = 0; *(str+i) != '\0'; i++);
return i;
Run Code Online (Sandbox Code Playgroud)
我认为他说它与算术计算有关,就像在第一个任何算术微积分完成时一样,但我无法理解,我看到它们都处于同一水平.换句话说,你能解释一下原因吗?
PS.我理解指针,我可以理解发生了什么,就像是通过一个单元逐步存储存储在"RAM单元"中的数组元素.
提前致谢.
Twitter会自动缩短通过api发布的t.co/???链接到链接.但是,您可以使用链接实体Twitter实体文档来屏蔽链接.但是,我找不到这个问题的任何明确答案:
实体的长度是否显示链接计数到140个字符,还是只计算t.co链接长度?
例:
39个字符
Hello this url is shortened: t.co/abcde
Run Code Online (Sandbox Code Playgroud)
此示例仍然链接到t.co/abcde但是长度为54个字符
Hello this url is shortened: www.entity-masked-url.com
Run Code Online (Sandbox Code Playgroud)
使用实体时哪一个是正确的长度?
我有一个字符串
String A;
Run Code Online (Sandbox Code Playgroud)
和一些处理它的方法
public void setA(String A) throws AInvalidException{
if(isAValid())
this.A = A;
throw new AInvalidException();
}
public boolean isAValid(){
int aLength = getA().length();
return b = (aLength==9) ? true: false;
}
public String getA(){
return A;
}
Run Code Online (Sandbox Code Playgroud)
当我试图在主要部分看到我的弦长
AClass.setA("123456789");
Run Code Online (Sandbox Code Playgroud)
它说我的String无效,调试后我看到我的String长度为零.我可能做错了什么?
每当我输入10个字符以下的密码时,它就会给我Password cannot exceed 10 characters.
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
String name = Name.getText();
String Username = uName.getText().toString();
String Pass1 = uPass.getPassword().toString();
String Confirm = uConfirm.getPassword().toString();
String Status = "OFFLINE";
int PassLen = Pass1.length();
if (Username.equals("") || Pass1.equals("") || Confirm.equals("") || name.equals(""))
{
JOptionPane.showMessageDialog(null, "You cannot leave any fields blank when creating an Account. Please Try Again");
}
else if ((uPass.getPassword().toString()).length()>10)
{
uPass.setText("");
uConfirm.setText("");
JOptionPane.showMessageDialog(null, "Password cannot exceed a maximum of 10 characters.");
}
else if (!Pass1.equals(Confirm))
{ …Run Code Online (Sandbox Code Playgroud) 我想查看列表有多长,但不使用该函数length.我写了这个程序,它不起作用.也许你可以告诉我为什么?谢谢!
let y = 0
main = do
list (x:xs) = list (xs)
y++
list :: [Integer] -> Integer
list [] = y
Run Code Online (Sandbox Code Playgroud) haskell functional-programming imperative-programming string-length
函数计算字符串长度; 我认为这里的逻辑是正确的:
int strlength(char *s)
{
int count=0;
while(*s!='\0')
{
count++;
s++;
}
return count;
}
int main(void) {
char *s;
int length;
printf("enter your string ");
scanf("%s",s);
length = strlength(s);
printf("string length:%d",length);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我在这里正确地接受了字符串并分配它吗?任何人都可以解释为什么我在这里得到分段错误?
在下面的代码中不确定为什么,但是当我们复制并粘贴变量"data"然后使用空白字符串时它显示长度为6.要测试是请复制相同的代码片段,即使我们工作正常创建一个具有相同名称的新变量(在下面的代码中注释).要测试的是请按原样复制和粘贴代码,因为只有复制粘贴它才会给它带来麻烦.
String data="??????"; // Copy this string variable, when we print this it gives output as 6
//String data=""; //This show's correct value as 0
System.out.println(data.length());
Run Code Online (Sandbox Code Playgroud) 目前正面临这一挑战.
// stringLengths takes in four strings
// it returns an array containing the length of each string
// Example: stringLengths('mushroom', 'onion', '', 'garlic') returns [8, 5, 0, 6]
function stringLengths(str1, str2, str3, str4) {
}
Run Code Online (Sandbox Code Playgroud)
肯定有
function stringLengths(str1, str2, str3, str4) {
var arr = [];
for (var i = 1; i < arguments.length; i++) {
arr.push(arguments[i].length);
}
return arr;
}
Run Code Online (Sandbox Code Playgroud)
这给我一个空数组.
如何将每个参数的length属性推入Array并返回每个参数的长度?
我正在尝试打印姓氏字符,但是我的代码正在生成异常。
码:
import java.util.Scanner;
public class LastCharacter {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.println("Type your name: ");
String name = reader.nextLine();
char nameLastChar = lastCharacter(name);
System.out.println("Last character = " + nameLastChar);
}
public static char lastCharacter(String text){
int last = text.length();
char lastChar = text.charAt(last);
return lastChar;
}
}
Run Code Online (Sandbox Code Playgroud)
例外:
线程“主”中的异常java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:7
我找不到错误,也不了解异常信息。