Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

String Code

String Code

String Code

How do I find the desire space position in the string ?

example :
 string = '69% wool 30% NYLON 1% Other'

can I find out the first space start with the position 11 ? Then it will return position 13 to me.

I can use Rat(), but it only can return the Last Space position of whole string . I want to search start from position 11 or any position.

any suggestion?

RE: String Code

Here is a function that takes a string and breaks it apart and places the elements into an array buy size using a space as the key.  It is not exactly want you want it to do but with about 5 minutes of work you can have it doing what you want.

*/Program   : function FILLARAY
*/System    :
*/Purpose   : breaks up a string into an array
*/Syntax    : = fillaray(string,array,size)
*/Returns   : Integer - lines - number of lines required to fill the array
*/Parameter : String  - string - the char string or database filed to break up
*/          : String  - array - the name of the array to use
*/          : Integer - size - the length of the array strings to be returned
*/Changes   : The array containing the string pieces
*/Requires  : THE ARRAY MUST BE DECLARED IN THE CALLING PROGRAM and passed by reference
*/Calls     :
*/Version   : 1.0
*/Dated     : 22 Nov 1993
*/Written By: David W. Grewe
*& Array Function
*/ Record Of Change
parameters pcStr , paArray , pnSize
*external array (paArray)  && before the days of reference passing
private pcStr, pnSize, paArray
pcStr = alltrim(pcStr) + " "
private lnCount, lnLen, lcStr, lnPlace
lnCount = 0                             && number of array elements used
lnLen = len(pcStr)                      && length of string to be worked on
lcStr = " "                             && swap var to hold a piece of pcStr
lnPlace = 0                             && where a blank space is
if len(pcStr) > pnSize
  do while len(alltrim(pcStr)) > 1
    lnCount = lnCount + 1
    dimension paArray(lnCount)
    lcStr = substr(pcStr , 1 , pnSize)
    lnPlace = rat(" " , lcStr)
    &paArray(lnCount) = alltrim(substr(pcStr , 1 , lnPlace))
    pcStr = substr(pcStr , lnPlace)
  lnCount = 1
  &paArray(1) = pcStr
return lnCount

David W. Grewe

RE: String Code

The following code will display the position of all "spaces" in your string in a wait window:

mPOS = ""
mString = "Return the location of spaces"
FOR I = 1 TO LEN(mString)
IF SUBSTR(mString, I,1) = CHR(32)
mPOS = mPOS + ALLTRIM(STR(I)) + ", "
WAIT "Spaces found at " + mPOS WINDOW

Modify the the IF/ENDIF to perform what ever task you want to do, or use the code as part of a procedure and pass it parameters.


RE: String Code

My $.02

(Based on the parameters you provided above)

lcString='69% wool 30% NYLON 1% Other'

lnFoundPos=AT(' ',lcSubString) && Returns 3 in this example

IF lnFoundPos > 0
  lnFoundPos=lnStartPos+lnFoundPos-1 && Returns 13
  Messagebox('Houston...We have a problem!',0,')

You could easily build this into a re-usable UDF by accepting the string to search, the string to search for, and the beginning position of the search as parameters.

Jon Hawkins

Carpe Diem! - Seize the Day!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close