2

IndexOf for chain space

 2 years ago
source link: https://www.codesd.com/item/indexof-for-chain-space.html
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.
neoserver,ios ssh client

IndexOf for chain space

advertisements

There is a space in the string, but when I run program, it returns -1, that means there aren't spaces in the string Here's the code:

import java.util.Scanner;

public class Main {

     public static void main(String[] args) {
         Scanner scan = new Scanner(System.in);
         String s = scan.next();
         System.out.println(s.indexOf(' '));
    }

}


Scanner.next() returns the next token in the input, and by default, tokens are whitespace separated. i.e. s is guaranteed not to contain spaces.

Maybe you meant String s = scan.nextLine();?

Related Articles

SystemTap support for user space application

I want to know how to add support in the systemtap for user space applications.When I am trying to trace any user space program, it is showing that CONFIG_UTRACE not set. Can somebody please help me out. It is needed very urgently.Perhaps utrace faci

WPF: OnKeyDown () Is Not Called for the Space Key in the WPF TextBox Derived Control

In a WPF application, I have a control that I have derived from TextBox like this: public class SelectableTextBlock : TextBox { protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); e.Handled = false; } } The OnKeyDown method is not

Disable selectivity for a space

I have the following HTML code: .meta { user-select: none; } .meta + .bash::first-letter { user-select: none; background-color: #ff0000; } <span class="meta">$</span> <span class="bash"> ls</span> Now I want the

Swift: Disable the bar button for white space / new line text in UITextView with placeholder text

I have a ViewController with a UITextView and a "Send" bar button item in the navigation bar which submits the text in the textView. Since the UITextView does not support placeholder text like the UITextField, I am handling it on my own with the

What size is too big for static space allocation

As I could not find a way out using thread specific data for socket descriptor as depicted in this question A question on shared library and thread specific data , I am planning to declare a process wide global array with each row having two elements

nested java for loop spaces and numbers

I can't seem to figure out how to figure this problem out. I want to add a number and remove a space on each line working down from 1. for (int line = 1; line <= 5; line++) { for (int space = 5; space >= line + 1; space--) { System.out.print("

Regular expression for @ after space in the text box

Write a regular expression for @ in some text, but @ must be after space only... Please help me... In this case am using AT JS Actually am problem is i need to make ajax call after @,followed by space as in the following scenario Screenshot of my pro

indexOf for several options

Let say, I get the following using var content = this.innerHTML: w here </div> Using indexOf (or other ways), I want to check for the first position that has either "Space", "<" or "&nbsp". In this case, it will

How to fix UTF encoding for white space?

In my C# code, I am extracting text from a PDF document. When I do that, I get a string that's in UTF-8 or Unicode encoding (I'm not sure which). When I use Encoding.UTF8.GetBytes(src); to convert it into a byte array, I notice that the whitespace is

Regular ruby ​​expression for chains with multiple patterns

i have a string with optional substrings and i was looking/working for/on regular expression with names captures, a single regular expression for all if possible. in RUBY Please help, sample strings: string1 = bike wash #a simple task string2 = bike

Chain space allowed, but not in first or last position

For a form validation I've to check input with javascript for valid names The string has to fit the following pattern. I may not start or end with a space It may contain spaces It may contain capital en lowercase letters, inclusive ê è en such It may

Search only for white spaces in a string in Flex

var sample:String = filterBox.text; Based on the String I get from TextInput, a Button has to be disabled if the String has only white spaces and enabled only otherwise. I want to check if the String has only white spaces. Is/Are there any inbuilt me

Php Validation: No Chain Space

I'm setting up a custom php form validation used in conjunction with wordpress contact form 7 plugin, I've set up a validation rule as the text field, I only want people to type 1 word (i.e. no spaces) and for that one word to begin with the letter s

Allocation of memory for chain and chart

I can't understand how memory is allocated in the following code: #include<stdio.h> #include<string.h> int main() { char a[]={"text"}; char b[]={'t','e','x','t'}; printf(":%s: sizeof(a)=%d, strlen(a)=%d\n",a, sizeof(a), str

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK