• Java Wild Card Queries
    10 replies, posted
I need to perform checks on Strings, although only on the first word of it... So, I would need a wildcard... How would I perform such an action?
[QUOTE=CountNoobula;23330471]I need to perform checks on Strings, although only on the first word of it... So, I would need a wildcard... How would I perform such an action?[/QUOTE] I'd start by exploding the string using spaces as delimiters (String.split()), and then use the first element you obtain for your checks. Was that what you needed or am I way of? code example: [cpp] String str = "Madrid Paris London"; String[] tokens = str.split(" ") ------------------------------------- tokens[0] = "Madrid"; tokens[1] = "Paris"; tokens[2] = "London"; [/cpp] note: my java is a bit rusty, no warranty on that code.
that is very close to what i need thanks :) ill implement it now and check if it works and suits the purpose [editline]06:16PM[/editline] now to addon to that, is there a way to count how many are in that array please? And to check if a value exists or isset? [editline]06:17PM[/editline] BTW it worked thanks :)
tokens.length(). And what do you mean by value? Like numbers?
no, i mean variable, lets say i want to check if the variable info exists, basically an equivalent to php's isset() function [editline]08:26PM[/editline] i have imported the following libraries [code]import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.net.*; import java.io.*; import java.util.*;[/code] But i get told it cant find the symbol method
Java is strongly typed. There is no use for a function like this in Java. What should that 'method' be for? You can write functions just like [code][modifiers] returntype functionname(args){ functionbody }[/code]
[QUOTE=CountNoobula;23333804]no, i mean variable, lets say i want to check if the variable info exists, basically an equivalent to php's isset() function[/QUOTE] If you want to check if a non atomic variable ( non int, double, boolean, ...) is set: check if the object is null ( if ( variable != null ) variable.foo(); ) If you want global variables like in php you'll have to use static class variables/methods. But honestly, this is basic Java knowledge..
no, you have mixed it up, i can write functions easily, but I try use your suggestion [code]command.length()[/code] to get the number of arrays in that, it prints out the error [code]symbol : method length() location: class java.lang.String[] textArea.append("> " + command.length()); ^ 1 error Process completed.[/code] [editline]09:00PM[/editline] @borsty, I dont want to check if is set... I want to check if it exists... that php code does both functions, sorry for the confusion
[QUOTE=CountNoobula;23334764]no, you have mixed it up, i can write functions easily, but I try use your suggestion [code]command.length()[/code] to get the number of arrays in that, it prints out the error [code]symbol : method length() location: class java.lang.String[] textArea.append("> " + command.length()); ^ 1 error Process completed.[/code] [editline]09:00PM[/editline] @borsty, I dont want to check if is set... I want to check if it exists... that php code does both functions, sorry for the confusion[/QUOTE] Try command.length instead of command.length(). The array functions are special.
yes! that works perfectly thank you
[QUOTE=CountNoobula;23330989]that is very close to what i need thanks :) ill implement it now and check if it works and suits the purpose [editline]06:16PM[/editline] now to addon to that, is there a way to count how many are in that array please? And to check if a value exists or isset? [editline]06:17PM[/editline] [B]BTW it worked thanks :)[/B][/QUOTE] Good to know. Good luck with whatever this project is
Sorry, you need to Log In to post a reply to this thread.