• Welcome to Valhalla Legends Archive.
 

Parsing letters

Started by Networks, June 23, 2004, 09:57 AM

Previous topic - Next topic

Networks

What's the best way to parse each letter in a sentence or word? Feanor told me a loop would be best from 0 to len(string) is there any other way?

Lenny

Be more specific, exactly what do you want out of the parsed information?
The Bovine Revolution
Something unimportant

Live Battle.net:

WARNING: The preceding message may have contained content unsuitable for young children.

Networks

#2
I want to see if that letter is inside another string.

BTW: Instr() won't work if I have to multiple letters for what I am doing.

Lenny

Are you trying to find the occurence of a series of letters in a string?
If that case, Instr() will work...I'm still uncertain as what you are trying to do.
The Bovine Revolution
Something unimportant

Live Battle.net:

WARNING: The preceding message may have contained content unsuitable for young children.

CrAz3D

I think an example would help us all figure it out.
rebundance - having or being in excess of sheer stupidity
(ré-bun-dance)
Quote from: Spht on June 22, 2004, 07:32 PMSlap.
Quote from: Adron on January 28, 2005, 09:17 AMIn a way, I believe that religion is inherently evil, which includes Christianity. I'd also say Christianity is eviller than Buddhism (has more potential for evil).
Quote from: iago on April 19, 2005, 01:06 PM
CrAz3D's ... is too big vertically, at least, too big with ... iago ...

Eli_1

#5
We're obviously having a misunderstanding. Either you're confused because you don't know InStr will return the FIRST occurance of something, regardless of how many there are, or we're confused and don't understand the question.

Tuberload

Quote from: Networks on June 23, 2004, 10:13 AM
I want to see if that letter is inside another string.

BTW: Instr() won't work if I have to multiple letters for what I am doing.

Perform a linear search.

Algorithm:
1) Set a location variable to 0.
2) Loop through the char array (string) until you come accrossed the desired element (char) or the end of the array.
2b) increment the location variable.
3) if location equals the length of the char array, set it to -1
4) return the location variable

This will produce either -1 if the character is not found, or the location of the character.

Example (java):
public static int linearSearch (char[] source, char element)
   {
      int location = 0;
      
      while ((source[location] != element) && (location < source.length))
         location++;
      
      if (location == source.length)
         location = -1;
      
      return location;
   }


Now this will only search for one character at a time, but you could easily modify it to find whole strings.
Quote"Pray not for lighter burdens, but for stronger backs." -- Teddy Roosevelt
"Your forefathers have given you freedom, so good luck, see you around, hope you make it" -- Unknown

Newby

Dim I as Integer
For I = 0 to Len(String)
   'Each character is Mid$(String, I, 1)
Next I
- Newby

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote<TehUser> Man, I can't get Xorg to work properly.  This sucks.
<torque> you should probably kill yourself
<TehUser> I think I will.  Thanks, torque.

Stealth

You will want to start the For loop at 1. Mid() is not zero-based.
- Stealth
Author of StealthBot

Networks

Quote from: Newby on June 23, 2004, 04:21 PM
Dim I as Integer
For I = 0 to Len(String)
   'Each character is Mid$(String, I, 1)
Next I


Is what I used and it works.

Eli_1

Eeek, then you're using On Error Resume Next - Shame.  :P

BinaryzL

Quote from: Newby on June 23, 2004, 04:21 PM
Dim I as Integer
For I = 0 to Len(String)
   'Each character is Mid$(String, I, 1)
Next I


That code will not work, like stealth said mid() starts from 1. (Plus why would you want on error resume next for a simple for loop????)

Newby

Quote from: Stealth on June 23, 2004, 05:17 PM
You will want to start the For loop at 1. Mid() is not zero-based.
I was deciding on putting 0 or 1. I figured I'd put 0 to be safe =P.
- Newby

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote<TehUser> Man, I can't get Xorg to work properly.  This sucks.
<torque> you should probably kill yourself
<TehUser> I think I will.  Thanks, torque.