“Temukan Ruang di String” Kode Jawaban

Temukan Ruang di String

public static boolean containsWhiteSpace(final String testCode){
    if(testCode != null){
        for(int i = 0; i < testCode.length(); i++){
            if(Character.isWhitespace(testCode.charAt(i))){
                return true;
            }
        }
    }
    return false;
}
Dangerous Dogfish

Temukan Ruang di String

def tt(w): 
    if ' ' in w: 
       print 'space' 
    else: 
       print 'no space' 

>>   tt('b ')
>> space
>>  tt('b b')
>> space
>>  tt('bb')
>> no space
Shy Shrike

Temukan Ruang di String

// C program to illustrate
// isspace() function
#include <ctype.h>
#include <stdio.h>
int main()
{
    // taking input
    char ch = ' ';
  
    // checking is it space?
    if (isspace(ch))
        printf("\nEntered character is space");
    else
        printf("\nEntered character is not space");
}
red-kid

Temukan Ruang di String

text = "This is simple extample for count spaces"
text.split(" ").length - 1;
Elated Eel

Temukan Ruang di String

// CPP program to count white spaces in a string
#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
  
// function to calculate whitespaces
void space(string& str)
{
    int count = 0;
    int length = str.length();
    for (int i = 0; i < length; i++) {
        int c = str[i];
        if (isspace(c))
            count++;
    }
    cout << count;
}
  
// Driver Code
int main()
{
    string str = "Geeks for geeks";
    space(str);
    return 0;
}
red-kid

Jawaban yang mirip dengan “Temukan Ruang di String”

Pertanyaan yang mirip dengan “Temukan Ruang di String”

Lebih banyak jawaban terkait untuk “Temukan Ruang di String” di C++

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya