Sponsored Content
Top Forums UNIX for Advanced & Expert Users test the string is char or integer Post 302244721 by joeyg on Wednesday 8th of October 2008 12:53:21 PM
Old 10-08-2008
Hammer & Screwdriver what about this approach?

Code:
> cat test_alpha 
sample1="abcdef"
echo $sample1 - checking alpha
if [ $sample1 = `echo $sample1 | tr -d [0-9]` ]; then  echo "same"; fi

sample2="abc123def"
echo $sample2 - checking alpha
if [ $sample2 = `echo $sample2 | tr -d [0-9]` ]; then  echo "same"; fi

sample3="123456"
echo $sample3 - checking numeric
if [ $sample3 = `echo $sample3 | tr -d [:alpha:]` ]; then  echo "same"; fi

sample4="123abc456"
echo $sample4 - checking numeric
if [ $sample4 = `echo $sample4 | tr -d [:alpha:]` ]; then  echo "same"; fi

and its execution; showing the first is alpha (same) and the third is all numeric (same)
Code:
> test_alpha 
abcdef - checking alpha
same
abc123def - checking alpha
123456 - checking numeric
same
123abc456 - checking numeric

 

9 More Discussions You Might Find Interesting

1. Programming

Integer to String

Which function should I use to convert an Integer to a String or Char format ? Thanx (2 Replies)
Discussion started by: psilva
2 Replies

2. Programming

C function to test string or integer

Hi everyone , Is there any predefined C function that tests whether an input is string or an integer? Thank's in advance :) (3 Replies)
Discussion started by: qqq
3 Replies

3. Programming

to compare two integer values stored in char pointers

How can I compare two integer values which is stored in char pointers? suppose I have char *a and char *b having values 10 and 20. how can i find the shorter value? (1 Reply)
Discussion started by: naan
1 Replies

4. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

5. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

6. Programming

I don't know how to replace input char with appropriate integer

Hi guys, I asked for help on programming forums and no one didn't helped me so I ask for help here. I am playing with some tasks from my book and I can't figure where did I get wrong. From the first program I get a blank screen, program won't generate 10*10 matrix. And second problem is I... (6 Replies)
Discussion started by: solaris_user
6 Replies

7. Shell Programming and Scripting

how to compare string integer with an integer?

hi, how to I do this? i="4.000" if ; then echo "smaller" fi how do I convert the "4.000" to 4? Thanks! (4 Replies)
Discussion started by: h0ujun
4 Replies

8. Shell Programming and Scripting

How do I test the first char of each line in an array

Hi folks, I am self-learning as I can I have a script that has read a file into an array. I can read out each line in the array with the code: for INDEX in {0..$LENGTH} ## $LENGTH was determined at the read in do echo "${data}" done What I need to do is test the first char... (2 Replies)
Discussion started by: Marc G
2 Replies

9. Shell Programming and Scripting

Perl Script Integer Test

Working out a small problem, I have a need of a Perl snippet which might look something like this: use integer; ... if ($changingNumber / 2) { do something; } else { do something else; } ... What I want to happen is for "if" to resolve as "true" every time a whole... (3 Replies)
Discussion started by: LinQ
3 Replies
NUMFMT_SET_ATTRIBUTE(3) 						 1						   NUMFMT_SET_ATTRIBUTE(3)

NumberFormatter::setAttribute - Set an attribute

	Object oriented style

SYNOPSIS
public bool NumberFormatter::setAttribute (int $attr, int $value) DESCRIPTION
Procedural style bool numfmt_set_attribute (NumberFormatter $fmt, int $attr, int $value) Set a numeric attribute associated with the formatter. An example of a numeric attribute is the number of integer digits the formatter will produce. PARAMETERS
o $fmt -NumberFormatter object. o $attr - Attribute specifier - one of the numeric attribute constants. o $value - The attribute value. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 numfmt_set_attribute(3) example <?php $fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL ); echo "Digits: ".numfmt_get_attribute($fmt, NumberFormatter::MAX_FRACTION_DIGITS)." "; echo numfmt_format($fmt, 1234567.891234567890000)." "; numfmt_set_attribute($fmt, NumberFormatter::MAX_FRACTION_DIGITS, 2); echo "Digits: ".numfmt_get_attribute($fmt, NumberFormatter::MAX_FRACTION_DIGITS)." "; echo numfmt_format($fmt, 1234567.891234567890000)." "; ?> Example #2 OO example <?php $fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL ); echo "Digits: ".$fmt->getAttribute(NumberFormatter::MAX_FRACTION_DIGITS)." "; echo $fmt->format(1234567.891234567890000)." "; $fmt->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, 2); echo "Digits: ".$fmt->getAttribute(NumberFormatter::MAX_FRACTION_DIGITS)." "; echo $fmt->format(1234567.891234567890000)." "; ?> The above example will output: Digits: 3 1.234.567,891 Digits: 2 1.234.567,89 SEE ALSO
numfmt_get_error_code(3), numfmt_get_attribute(3), numfmt_set_text_attribute(3). PHP Documentation Group NUMFMT_SET_ATTRIBUTE(3)
All times are GMT -4. The time now is 12:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy