answersLogoWhite

0


Best Answer

In C++, the return value will be an empty string because 2 is equal to the string length (the second parameter, 4, is simply ignored). If the first parameter were greater than the string length, an out_of_range exception will be thrown instead.

User Avatar

Wiki User

6y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: If String str US then what is the value of str.substring(2 4)?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How does one use string to int Java?

Yes as long as the value of the string is an integer. String str = "12345"; int i = Integer.parseInt(str); Note: This code would work very well for strings that have numeric values inside. If your string can contain any kind of data, remember to surround this code with a try catch block to ensure that you don't get an exception that crashes your system. Some of us usually miss the try catch block expecting ideal input. But once in a while we get some data that is different to what we are expecting in our code which crashes our system. Instead of spending hours trying to figure out what crashed our app, its easier to have a catch block do the work :)


String In JAVA language?

In Java, literal character strings such as "foo" are implemented as instances of the String class. These strings are constant and can not be modified directly. Mutable character strings, or string variables, are implemented as instances of StringBuffer class. It is also possible to work directly with arrays of chars, but String and related classes offer lots of useful methods.


Manupulating strings and arrays together in c plus plus?

A string is an array; an array of character data types (char or wchar_t). Therefore anything you can do with an array you can also do with a string. C does not have a built-in type for either an array or a string, but C++ does. In C, the programmer was entirely responsible for managing the memory allocated to an array. Built-in functions allowed us to determine the length of a null-terminated string, append strings, or alter the amount of memory allocated to an array, but the functions and the arrays were entirely separate. With C++, std::vector and std::string objects allow us to manipulate dynamic arrays and variable length strings, respectively, without having to worry about the underlying memory allocations. Since all the required methods are encapsulated within the objects themselves, they are much easier to work with. For instance, in C, if we wanted to determine the length of a string we might call the strlen function: char* str = "Hello world!"; unsigned size = strlen (str); Arrays are a bit more difficult in that we must maintain a separate variable to keep track of an array's length: unsigned size = 10; int* arr = malloc(size); size = 11; arr = realloc(arr, size); In C++, strings and arrays know their own length, so we don't need to call external functions or maintain separate variables: std::string str = "Hello world!"; std::cout << '"' << str << '"' << " has " << str.size() << " characters\n"; std::vector<int> vect(10,0); std::cout << "vect has " << vect.size() << " elements\n"; A vector of strings allows us to manipulate strings and vectors together. A vector of strings is essentially a two-dimensional dynamic array where each row is a string, and every string can have different lengths. The following therefore creates a vector with 10 empty strings: std::vector< std::string > vstrings (10, ""); We can then manipulate each of the individual strings in the array: vstrings[0] = "Hello world!"; vstrings[1] = "Another string."; vstrings[2] = "The third string."; ... vstrings[9] = "The string to end all strings."; Each of these strings is a different length. With a traditional two-dimensional array each row would be the same length. In this case we'd need at least a 10 x 31 array (including null-terminators), which wastes memory when any string is less than 30 characters long. The only way to resolve this is to use a one-dimensional array of pointers to strings instead. Vectors of strings do the same thing, but they are much easier to work with since all memory management is handled by the objects themselves.


What is string class?

Strings are probably one of the most commonly used java data-types. They can hold almost anything that are enclosed within a pair of double quotes and hence are very versatile and powerful. This chapter covers the String class.Strings Are Immutable ObjectsHandling "strings" of characters is a fundamental aspect of most programming languages. In Java, each character in a string is a 16-bit Unicode character. Because Unicode characters are 16 bits, a rich, international set of characters is easily represented in Unicode.In Java, strings are objects. Just like other objects, you can create an instance of a String with the new keyword, as follows:String s = new String();This line of code creates a new object of class String, and assigns it to the reference variable s. So far, String objects seem just like other objects. Now, let's give the String a value:s = "abc";As you might expect, the String class has about a zillion constructors, so you can use a more efficient shortcut:String s = new String("abc");And just because you'll use strings all the time, you can even say this:String s = "abc";There are some subtle differences between these options that we'll discuss later, but what they have in common is that they all create a new String object, with a value of "abc", and assign it to a reference variable s. Now let's say that you want a second reference to the String object referred to by s:String s2 = s; //refer s2 to the same String as sString objects seem to be behaving just like other objects, so how is it that they are Immutable? Once you have assigned a String a value, that value can never change-it's immutable, frozen solid, won't change. The good news is that while the String object is immutable, its reference variable is not, so to continue with our previous example:s = s.concat(" efg");// the concat() method 'appends' a literal to the endDidn't I just say that Strings are immutable? Yes, I perfectly did. But, here the stuff within the double quotes that is passed as argument to the concat method gets appended to the end of the String s. How did this happen?The VM took the value of String s (which was "abc"), and added or rather appended " efg" onto the end, giving us the value "abc efg". Since Strings are immutable, the VM couldn't stuff this new value into the old String referenced by s, so it created a new String object, gave it the value "abc efg", and made s refer to it. At this point in our example, we have two String objects: the first one we created, with the value "abc", and the second one with the value "abc efg". Technically there are now three String objects, because the literal argument to concat, " efg", is itself a new String object. But we have references only to "abc" (referenced by s2) and "abc efg" (referenced by s).Note, however, that the original "abc" String didn't change; only the reference variable s was changed, so that it would refer to a different String.To wrap up, the original variable 's' in which we had "abc" as value would be abandoned and a new value "abc efg" would get assigned to it as soon as the s.concat(" efg") line of code is executed.


Can you specify variable field width in scanf format string?

AnswerYou can't specify a variable field with a fixed format string, but you can get around this by making the format string variable:int width; char format[20]; /* or whatever size is appropriate */ int value; ... sprintf(format, "%%%dd", width); /* generates a string like "%5d" */ scanf(format, &value); The only drawback to this method, other than requiring two statements, is that the compiler can't do a sanity check on the arguments to scanf like it can when the format is a string constant.AnswerIf you want to specify a variable width in a printf format string (as opposed to scanf), you can do the following:printf("%*d", width, num);That will use the value of "width" as the width for formatting the value of "num" as a decimal integer.

Related questions

How many bytes does a string occupy in c?

Depends on several factors:number of bytes per character: 1 to 4 depending on which alphabet and character encoding you use. 1 byte per character for US-ASCII and the most common Western Europe encodings.length of the string: bytes per character times number of charactersprogramming language: in C, the string takes up no more space than the characters do. In many other languages, there is an additional fixed overhead for the string object itself. For example in Java, a string takes 2-4 bytes plus the space taken by the characters.


How does one use string to int Java?

Yes as long as the value of the string is an integer. String str = "12345"; int i = Integer.parseInt(str); Note: This code would work very well for strings that have numeric values inside. If your string can contain any kind of data, remember to surround this code with a try catch block to ensure that you don't get an exception that crashes your system. Some of us usually miss the try catch block expecting ideal input. But once in a while we get some data that is different to what we are expecting in our code which crashes our system. Instead of spending hours trying to figure out what crashed our app, its easier to have a catch block do the work :)


String In JAVA language?

In Java, literal character strings such as "foo" are implemented as instances of the String class. These strings are constant and can not be modified directly. Mutable character strings, or string variables, are implemented as instances of StringBuffer class. It is also possible to work directly with arrays of chars, but String and related classes offer lots of useful methods.


How string are handle in java?

Handling "strings" of characters is a fundamental aspect of most programming languages. In Java, each character in a string is a 16-bit Unicode character. Because Unicode characters are 16 bits, a rich, international set of characters is easily represented in Unicode. In Java, strings are objects. Just like other objects, you can create an instance of a String with the new keyword, as follows: String s = new String(); This line of code creates a new object of class String, and assigns it to the reference variable s. So far, String objects seem just like other objects. Now, let's give the String a value: s = "abc"; As you might expect, the String class has about a zillion constructors, so you can use a more efficient shortcut: String s = new String("abc"); And just because you'll use strings all the time, you can even say this: String s = "abc"; There are some subtle differences between these options that we'll discuss later, but what they have in common is that they all create a new String object, with a value of "abc", and assign it to a reference variable s. Now let's say that you want a second reference to the String object referred to by s: String s2 = s; //refer s2 to the same String as s String objects seem to be behaving just like other objects, so how is it that they are Immutable? Once you have assigned a String a value, that value can never change-it's immutable, frozen solid, won't change. The good news is that while the String object is immutable, its reference variable is not, so to continue with our previous example: s = s.concat(" efg"); // the concat() method 'appends' a literal to the end Didn't I just say that Strings are immutable? Yes, I perfectly did. But, here the stuff within the double quotes that is passed as argument to the concat method gets appended to the end of the String s. How did this happen? The VM took the value of String s (which was "abc"), and added or rather appended " efg" onto the end, giving us the value "abc efg". Since Strings are immutable, the VM couldn't stuff this new value into the old String referenced by s, so it created a new String object, gave it the value "abc efg", and made s refer to it. At this point in our example, we have two String objects: the first one we created, with the value "abc", and the second one with the value "abc efg". Technically there are now three String objects, because the literal argument to concat, " efg", is itself a new String object. But we have references only to "abc" (referenced by s2) and "abc efg" (referenced by s). Note, however, that the original "abc" String didn't change; only the reference variable s was changed, so that it would refer to a different String. To wrap up, the original variable 's' in which we had "abc" as value would be abandoned and a new value "abc efg" would get assigned to it as soon as the s.concat(" efg") line of code is executed.


Manupulating strings and arrays together in c plus plus?

A string is an array; an array of character data types (char or wchar_t). Therefore anything you can do with an array you can also do with a string. C does not have a built-in type for either an array or a string, but C++ does. In C, the programmer was entirely responsible for managing the memory allocated to an array. Built-in functions allowed us to determine the length of a null-terminated string, append strings, or alter the amount of memory allocated to an array, but the functions and the arrays were entirely separate. With C++, std::vector and std::string objects allow us to manipulate dynamic arrays and variable length strings, respectively, without having to worry about the underlying memory allocations. Since all the required methods are encapsulated within the objects themselves, they are much easier to work with. For instance, in C, if we wanted to determine the length of a string we might call the strlen function: char* str = "Hello world!"; unsigned size = strlen (str); Arrays are a bit more difficult in that we must maintain a separate variable to keep track of an array's length: unsigned size = 10; int* arr = malloc(size); size = 11; arr = realloc(arr, size); In C++, strings and arrays know their own length, so we don't need to call external functions or maintain separate variables: std::string str = "Hello world!"; std::cout << '"' << str << '"' << " has " << str.size() << " characters\n"; std::vector<int> vect(10,0); std::cout << "vect has " << vect.size() << " elements\n"; A vector of strings allows us to manipulate strings and vectors together. A vector of strings is essentially a two-dimensional dynamic array where each row is a string, and every string can have different lengths. The following therefore creates a vector with 10 empty strings: std::vector< std::string > vstrings (10, ""); We can then manipulate each of the individual strings in the array: vstrings[0] = "Hello world!"; vstrings[1] = "Another string."; vstrings[2] = "The third string."; ... vstrings[9] = "The string to end all strings."; Each of these strings is a different length. With a traditional two-dimensional array each row would be the same length. In this case we'd need at least a 10 x 31 array (including null-terminators), which wastes memory when any string is less than 30 characters long. The only way to resolve this is to use a one-dimensional array of pointers to strings instead. Vectors of strings do the same thing, but they are much easier to work with since all memory management is handled by the objects themselves.


What is the value of us mint 25.00 golden dollars?

Dollar coins dated 1971 and later are only worth face value unless in mint packaging. If you have a mint roll of them (as in, it says US mint, NOT String and Son or any other brand) your rolls might be worth $27-30, though it would be hard to find a buyer. If your rolls do not say US mint on them, they are only worth face value, $25.


When one light on a string of lights burns out and the entire string turn off this indicates to us that the lights are wired In a?

series


What is string class?

Strings are probably one of the most commonly used java data-types. They can hold almost anything that are enclosed within a pair of double quotes and hence are very versatile and powerful. This chapter covers the String class.Strings Are Immutable ObjectsHandling "strings" of characters is a fundamental aspect of most programming languages. In Java, each character in a string is a 16-bit Unicode character. Because Unicode characters are 16 bits, a rich, international set of characters is easily represented in Unicode.In Java, strings are objects. Just like other objects, you can create an instance of a String with the new keyword, as follows:String s = new String();This line of code creates a new object of class String, and assigns it to the reference variable s. So far, String objects seem just like other objects. Now, let's give the String a value:s = "abc";As you might expect, the String class has about a zillion constructors, so you can use a more efficient shortcut:String s = new String("abc");And just because you'll use strings all the time, you can even say this:String s = "abc";There are some subtle differences between these options that we'll discuss later, but what they have in common is that they all create a new String object, with a value of "abc", and assign it to a reference variable s. Now let's say that you want a second reference to the String object referred to by s:String s2 = s; //refer s2 to the same String as sString objects seem to be behaving just like other objects, so how is it that they are Immutable? Once you have assigned a String a value, that value can never change-it's immutable, frozen solid, won't change. The good news is that while the String object is immutable, its reference variable is not, so to continue with our previous example:s = s.concat(" efg");// the concat() method 'appends' a literal to the endDidn't I just say that Strings are immutable? Yes, I perfectly did. But, here the stuff within the double quotes that is passed as argument to the concat method gets appended to the end of the String s. How did this happen?The VM took the value of String s (which was "abc"), and added or rather appended " efg" onto the end, giving us the value "abc efg". Since Strings are immutable, the VM couldn't stuff this new value into the old String referenced by s, so it created a new String object, gave it the value "abc efg", and made s refer to it. At this point in our example, we have two String objects: the first one we created, with the value "abc", and the second one with the value "abc efg". Technically there are now three String objects, because the literal argument to concat, " efg", is itself a new String object. But we have references only to "abc" (referenced by s2) and "abc efg" (referenced by s).Note, however, that the original "abc" String didn't change; only the reference variable s was changed, so that it would refer to a different String.To wrap up, the original variable 's' in which we had "abc" as value would be abandoned and a new value "abc efg" would get assigned to it as soon as the s.concat(" efg") line of code is executed.


How is popcorn used in chirtmas decoration in the US?

string it and hang on tree


What us the decimal of 3 days in a week?

It is 0.428571 with the underlined string repeating.


Can you specify variable field width in scanf format string?

AnswerYou can't specify a variable field with a fixed format string, but you can get around this by making the format string variable:int width; char format[20]; /* or whatever size is appropriate */ int value; ... sprintf(format, "%%%dd", width); /* generates a string like "%5d" */ scanf(format, &value); The only drawback to this method, other than requiring two statements, is that the compiler can't do a sanity check on the arguments to scanf like it can when the format is a string constant.AnswerIf you want to specify a variable width in a printf format string (as opposed to scanf), you can do the following:printf("%*d", width, num);That will use the value of "width" as the width for formatting the value of "num" as a decimal integer.


Which us state is not in north america?

Hawaii is the only US state that is not in North America, being a string of islands in the Pacific.