BasicsTutorial/More on Strings…

Last-modified: 2009-11-28 (土) 20:44:07

More on Strings…

文字列の上でより多くの

That's right… MORE on strings, because there is a lot to do with them.
それらでする多くがあるので、それはより文字のright…である。

Looking into a string to see what it is or what is in it is called parsing.
それが何であるかについて見る文字またはそれの中にあることを調べることは、分析と呼ばれている。
Things (e.g. programs) that look into strings are called parsers.
文字列を調べるものは、パーサーと呼ばれている。(例えばプログラム)
We are going to learn how to parse strings with DBPro.
我々は、DBProで文字列を解析する方法を学ぶつもりである。
We’ll start off simply…
我々は、単純に始める

LEN()

Input “Type something: ”,string$
Length = len(string$)
Print “Your string was “,length,” characters long”
Wait key

We see a new command here - LEN().
我々は、新しい命令をここで見る - LEN()。
This command returns the length in characters of the string specified.
この命令は、指定される文字列の文字数を、長さを返す。
So LEN(“Hello”) = 5, LEN(“What’s going on?”) = 16.

This is a very simple form of parsing, but the LEN() command is very useful as it tells us how many characters we have to look at.
これはそうである 非常に単純な分析の生まれる、しかし、LEN()、それが我々がどれくらいのキャラクタを見なければならないかについて我々に話すように、命令は非常に役に立つ。

MID$()

The next command we will look at is MID$().
我々が見る 次の命令は、MID$()である。

Input “Type a string: ”,string$
repeat
  Input “Choose a number less than or equal to ”,len(string$),”: ”,pos
until pos <= len(string$)
character$ = mid$(string$,pos)
print “Character ”,pos,” in the string ‘”,string$,”’ is ‘”,character$,”’”
wait key

MID$() returns the character at the specified position in the specified string.
MID$()、指定された文字列で指定された位置にある1文字を返す。
So therefore…
それで、therefore…

Mid$(“Hello”, 4) = “l”
Mid$(“What???”, 1) = “W”
Mid$(“You!”, 4) = “!”

Simple enough.
十分に単純な。
Now with these two simple commands you can do pretty much any parsing you want to a string.
現在これらの2つの単純なコマンドを使って、あなたが文字に望むどんな分析でもすることができる。
Here is an example that checks if a string is within another string.
文字がもう一つの文字の範囲内であるかどうかについて調べる例が、ここにある。
We will go through this and then I hope you will be able to do the many tasks for this section ;).
我々はこれを通り抜ける、それから、私はあなたがこのセクションのために多くの仕事を行うことができることを望む;)。

print stringInString("hello","3214hello")
print stringInString("hello","4hellojdf")
print stringInString("hello","4hllojf")
wait key
end
`Find if a string is in another string, if it is return the starting place in the checked string
`『それがチェックされた文字列で始まっている場所でRETURNであるならば、文字がもう一つの文字であるかどうか突き止めなさい
function stringInString(inString$, checkString$)
     inStringLen = len(inString$)
     checkStringLen = len(checkString$)
     `If strings are the same then string occurs at the first character
     if inString$ = checkString$ then exitfunction 1
     `If inString$ is longer than checkString$ then it is impossible for it to be in it
     if inStringLen > checkStringLen then exitfunction 0
     `Loop through the checkString$ to find the start character of inString$
     for x=1 to checkStringLen-inStringLen+1
           `Set the place in the inString$ to start checking (the beginning)
           y = 1
           `While the checkString$ character equals the inString$ character, keep looping through the inString
           while mid$(checkString$,x+y-1) = mid$(inString$,y)
                 if y = inStringLen then exitfunction x
                 inc y
           endwhile
     next x
     `If no occurences are found return a 0
endfunction 0

The top of the code is just an example to show the function in action.
コードのトップは、活動中に関数を示すちょうど例である。
It’s pretty simple how it works.
それがどのように働くかは、かなり単純である。
It prints the value returned from the function (i.e. The position of the string in the string, or 0 if it’s not there).
それは、関数(すなわち、それがそこにないならば文字列または0の文字列の位置)から返される値をプリントする。

1

First of all we have these two lines…
まず第一に、我々はこれらの2つの行を持つ

     inStringLen = len(inString$)
     checkStringLen = len(checkString$)

This is so that we only have to check the length of the strings twice, it saves processing time and makes the code neater.
これはそう、我々が二回文字列の長さをチェックしなければならないだけであるということである、それは時間を処理して節約して、コードをよりきちんとしているようにする。
Next we have this…
次に、我々はこれを持つ

2

     `If strings are the same then string occurs at the first character
     if inString$ = checkString$ then exitfunction 1
     `If inString$ is longer than checkString$ then it is impossible for it to be in it
     if inStringLen > checkStringLen then exitfunction 0

The first line is to check if the strings are exactly the same.
最初の行は、文字列が正確に同じことであるかどうか調べることである。
If they are then there is absolutely no point in checking the string further, we just return a 1 to say that the string was found at the first character.
それがそうであるならば、更なる文字列をチェックする意味が全然なくて、ちょっと我々は1を返す最初のキャラクタで見つかったと言うために。
Next we start a loop using for next…
我々が ループを始める次に

3

     `Loop through the checkString$ to find the start character of inString$
     for x=1 to checkStringLen-inStringLen+1
           `Set the place in the inString$ to start checking (the beginning)
           y = 1

This loops through the string that is being checked, checkString$.
これは、チェックされている文字列を通して輪になる、checkString$。
We loop from it’s beginning to the end of it, minus the length of the inString$.
我々は、それから輪で囲む、inString$.の長さなしで、それの終わりまで始まる
This is because there is no point checking 2 characters from the end if we are checking for a 5 character string for example.
我々がたとえば5つの文字列について調べているならば終わりから2つのキャラクタをチェックしている点がないので、これはそうである。
After that we set the position that we are going to check in the inString to the beginning.
その後、我々は我々が始めにinStringする際にチェックするつもりであるという位置をセットした。
Next code…
次のcode…

4

           `While the checkString$ character equals the inString$ character, keep looping through the inString
           while mid$(checkString$,x+y-1) = mid$(inString$,y)
                 if y = inStringLen then exitfunction x
                 inc y
           endwhile

Now that we have started looping the checkString$, we need to compare it against the inString$ to see if they are the same.
我々がcheckString$を輪で囲み始めた今、我々はそれが同じことであるかどうか見るためにinString$に対してそれを比較する必要がある。
We do this with a while loop, so first of all it checks if the first characters are the same.
我々はwhileループでこうするので、まず第一に、それは最初のキャラクタが同じことであるかどうか調べる。
If they are it keeps on checking, incrementing y to loop through the inString$ until the characters aren’t the same.
それがいるならば、それはチェックし続ける。そして、キャラクタが同じことでないまで、inString$を通して輪で囲むyを増加させる。
If the characters are all the same then the counter y will reach the end of the inString$.
キャラクタが全ての同じことであるならば、カウンタ yはinString$の終わりに達する。
This means we have found the string and can exit the function and return it’s position, x.
これは、我々が文字列を見つけて、関数を出ることができて、それが x位置であると答えることを意味する。
Otherwise the loop will keep going…
さもなければ、ループはgoing…を保つ

5

     next x
     `If no occurences are found return a 0
`『occurencesが見つからないならば、0を返しなさい
endfunction 0

Until it either finds the word or reaches the end of the for-next loop, in which case the function will end and return 0 having found nothing.
それが語を見つけるか、for-nextループの終わりに達するまで、その場合には、関数は終わる、そして、RETURN0が何も見つけなかった。

Hope you got that, if not read it through again and you will understand.
二度とそれを読まれないならば、あなたがそれを得たことを望みなさい、そして、あなたはわかる。
Parsing can be very useful at times so learn it well.
分析は時々非常に役に立つことがありえて、それで、よくそれを学ぶことがありえる。

etc

A few more commands to learn to do with strings are…
文字列ですることを学びなさいという もう少しの命令

LEFT$()
RIGHT$()
LOWER$()
UPPER$()
SPACE()

The last one is a parsing command like what we just did.
最後のものは、我々がちょうどしたことのような分析命令である。
It finds the number of spaces in a string.
それは、スペースの数を文字で発見する。
Now for the summary and lots o’ tasks…
現在概要と多くoのために』tasks…

Summary of Commands

命令の概要

· LEN$(string) - Returns the length of a string in characters.
LEN$(文字)は、キャラクタの文字の長さを返す。

· MID$(string, position) - Returns the character at the specified position in a string.
MID$(文字(位置))は、文字列の指定された位置のキャラクタを返す。

· LEFT$(string, quantity) - Returns the specified number of leftmost characters in a string.
LEFT$(文字(量))は、文字列の最も左から指定された数のキャラクタを返す。

· RIGHT$(string, quantity) - Returns the specified number of rightmost characters in a string.
RIGHT$(文字(量))は、文字列の最も右から指定された数のキャラクタを返す。

· LOWER$(string) - Returns the string in all lower case.
LOWER$(文字)は、全ての小文字の文字列を返す。
Useful when you don’t want case sensitive parsing.
あなたが大文字と小文字の区別ができる分析を望まないとき、役に立つ。

· UPPER$(string) - Returns the string in all upper case.
UPPER$(文字)は、全ての大文字の文字列を返す。
Useful when you don’t want case sensitive parsing.
あなたが大文字と小文字の区別ができる分析を望まないとき、役に立つ。

· SPACE(string) - Returns the number of spaces in a string.
SPACE(文字)は、文字のスペース(空白)の数を返す。

End of Section Tasks

セクション終わりの作業

l Improve the stringInString() function so that you can specify an occurrence number.
stringInStringすることを改善する()、あなたが出来事番号を指定することができるように、関数しなさい。
So if you had a string “hellohello” and you specified an occurrence of 2 and an inString of “hello”, it would return the position of the second occurrence of “hello”, 6.
あなたが文字「hellohello」を持つ、そして、あなたが2と「よろしく」のinStringの発生を指定するように、それはそうするRETURN「よろしく」(6)の第2の発生の位置。

l Write a function that flips the case of all the characters in a string, so “HeLlO” would become “hElLo”.
文字で全てのキャラクタのケースを放る関数を記述しなさいので、「よろしく」は「よろしく」になる。
You should return the flipped version from the function.
あなたは、関数から放られたバージョンを返さなければならない。

l Write a function that returns a string reversed.
逆にされる文字を返す関数を記述しなさい。

l Write a function that creates translates regular sentences to pig latin.
それが作成する関数がブタlatinに普通の文を翻訳すると書きなさい。
So “Hello my name is Joseph” would become “elloHay ymay amenay siay osephJay”.
「こんにちは、私の名前は、ジョセフである」ように、似合われた「elloHay ymay amenay siay osephJay」はそうする。
You will need to check for when new words start and end and handle each word separately.
あなたは、新語がいつのために始まって、終わって、別に各々の語を取り扱うか調べる必要がある。
I advise you use arrays to store information.
私は、あなたが情報を格納するために配列を使うと忠告する。
Remember to use LOCAL.
ローカルを使うのを忘れてはいけない。

l Make a function that clips a string.
文字を音を落す関数を行いなさい。
Specify a start and an end point for the clipping.
クリッピングのためにスタートと終点を指定しなさい。

l Make a function that takes out specified characters in a string.
文字で指定されたキャラクタを取り出す関数を行いなさい。

l Make a function that returns the number of words in a string.
文字で語の数を返す関数を行いなさい。

l I’m sure you can think of plenty more if you want.
私は、あなたが望むならば、あなたがよりたくさんについて考えることができると確信する。