Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #15901

Re: find a space in a string, better fast solution?

From Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups comp.lang.php
Subject Re: find a space in a string, better fast solution?
Date 2015-11-14 09:18 -0500
Organization A noiseless patient Spider
Message-ID <n27fnd$ktr$1@dont-email.me> (permalink)
References <n2744a$2v9$1@speranza.aioe.org>

Show all headers | View raw


On 11/14/2015 5:58 AM, albert wrote:
> If I have this
> xx/yy/178 234 38
> the space are only between the numbers (if there are number)
> 
> which is the most fast solution for know if after first number there is
> a space?
> 
> 1 Find the space for all the string       ?
> 2 find the space after last occurency /   ?
> 
> 
> 
> I need to do this:
> I can have this
> xx/yy/178 234 38    I have 2 spaces: do nothing
> xx/yy/200           No spaces:       take the value 200
> xx/yy/200 45        I have 1 space: do nothing
> xx/yy/             I have 1 space: do nothing because haven't the number
> 
> If in the string I have one space I do nothing
> If I haven't space I need take first(and the unique) number
> 
> 

OK, you could use several different ways (again, speed is not as
important as readability and maintainability).  Again, a regex is
overkill for something so simple.

So it looks like you're only concerned of the times when you have no
spaces in your string, but have one value.

First thing I would do is get rid of any leading and trailing white
space using trim:

$str1 = trim($str);

Then I would use the previous examples to extract the numbers and see
how many spaces (and numbers) you have.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

Back to comp.lang.php | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

find a space in a string, better fast solution? albert <alstopspam@stopaspam.com> - 2015-11-14 11:58 +0100
  Re: find a space in a string, better fast solution? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-11-14 13:08 +0100
  Re: find a space in a string, better fast solution? Jerry Stuckle <jstucklex@attglobal.net> - 2015-11-14 09:18 -0500

csiph-web