Questions tagged [string-length]

String length most commonly refers to the number of characters contained within a string. However, it could also mean the screen space a string takes up when printed.

This tag should be used for either of the two following types of questions:

  1. Those dealing with the number of characters contained within a string.
  2. Those dealing with measuring the size of a string (in pixels, millimeters, etc.) when it is printed on a screen.
1040 questions
-2
votes
2 answers

Calculate length of string without using strlen() function

Having a doubt regarding a very simple C code. I wrote a code to calculate the length of a string without using the strlen function. The code below works correctly if i enter a string with no spaces in between. But if i enter a string like "My name…
Sangeetha
  • 485
  • 2
  • 9
  • 24
-2
votes
1 answer

String is correct length but still getting error

Programming in Android/Java. I get both the log error message and the popup alert when string length is both correct or incorrect. I have attempted to flip the if-else statement and use (txtVin.length() ==17) but that isn't working either. Any…
-2
votes
1 answer

substr() fails when hyphen last character

I'm creating a site where users click on DIVs that look like a phone dialpad. When there are 3 or 7 characters, I add a hyphen to simulate the appearance of a phone number. However, when they press the backspace button, it will not subtract the…
-2
votes
1 answer

UTF8 correct string length with vardump

How can I make var_dump like output from an array that manages string characters length well, that is the same counts with and without accents? /var/www/test.php:4: array (size=2) 0 => string 'qwertzuiop' (length=10) 1 => string 'qwértzúíóp'…
-2
votes
3 answers

Stuffing date (HH:MM:SS) with nulls - str.length on a number returns undefined

In a web game I am trying to display remaining time in HH:MM:SS format - by using the following code (the backend sends remaining epoch timestamps as game.expire1 and game.expire2 via Websockets): var expireDiv1 = $('#expire1'); var expireDiv2 =…
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
-2
votes
2 answers

Subtracting from the length of an array

Need clarification on the below. Answer is "dog" and would like to know why. Example: var animals = ["parrot", "cat", "dog"]; console.log(animals[animals.length - 1]); Console = "dog".
-2
votes
3 answers

Comparing string lengths in C#

I need to make function that determine longer word of two entered. I have tried to use if-statement and String.Length, but I can't get it right. What would be the best way to make the function? Below is the main program. using System; using…
CrazyIvan
  • 31
  • 1
  • 2
-2
votes
1 answer

Finding minimum String length of all lines in a CSV and printing them

So let's say I have a CSV file of random alphabets in columns for example's sake: a wrrq jt pkto b They are in String format and I want to be able to find the minimum String length in this CSV list. In the example given, the minimum being 1 (the…
Weissman
  • 11
  • 4
-2
votes
1 answer

Invalid length parameter passed to the LEFT or SUBSTRING function error

I have the following code but I am getting the error, Msg 537, Level 16, State 3, Line 1 Invalid length parameter passed to the LEFT or SUBSTRING function. Code: SELECT Main.HostName, LEFT(Main.Users, Len(Main.Users) - 1) AS…
Dean Flaherty
  • 351
  • 1
  • 5
  • 15
-2
votes
3 answers

How to get a length of a String by using 1 method? SHORTER

It's really easy to get the length of a single string and return it's value! public static int length(String s){//trys and returns length of any string try{//try code len = s.length();//gets the length of any string }catch…
-2
votes
3 answers

How to find the length of a string in one line in C programming?

Here is a small snipped of code. int len(char *str) { int count = 0; while(*str++) count++; return count; } Now few days back I found a code which was able to this in one line. Basically there was some one line code in while's…
Jack Bary
  • 63
  • 1
  • 6
-2
votes
1 answer

Re Invalid length parameter passed to the RIGHT function

I am stuck with this error and unable to progress. Any idea on this error? CASE WHEN mm.[Moodle Courses Category] + '_' +ISNULL(RIGHT(ttg.TTGP_Group_Code, LEN(ttg.TTGP_Group_Code)-11),'V1') like '%/%' THEN mm.[Moodle Courses Category] + '_'…
Aruna Raghunam
  • 903
  • 7
  • 22
  • 43
-2
votes
2 answers

Why is strlen() about 20 times faster than manually looping to check for null-terminated character?

The original question was badly received and got many downvotes. So I thought I'd revise the question to make it easier to read and hopefully to be of more help to anyone seeing it. The original question was why strlen() was 20 times faster than…
Zebrafish
  • 11,682
  • 3
  • 43
  • 119
-2
votes
1 answer

Generate random binay String of fixed length in Java

I have the code below and all I want is to create a random binary of fixed length (eg 4 bits). I want 4 bits to be used. I want it like that because after that I need to store it in a byte array (eg byte[][] myArray = new byte [2][0]) public String…
elli
  • 1,109
  • 1
  • 13
  • 20
-2
votes
1 answer

Why this two seemingly same declarations results in different string length?

Can anyone explain why this code: char t1[20]; char t2[20]; memset(t1, 'B', sizeof(t1)); memset(t2, 'B', sizeof(t2)); printf("%lu\n", strlen(t1)); printf("%lu\n", strlen(t2)); result in: 22 21 Thank's
HB7
  • 5
  • 3