Jump to content

need a function 4 this task!


Piyush
 Share

Recommended Posts

I need a function 4 this..for eg

if i input this string

'this i the {[first|last|third]} {[tym|time]} i m saying this to u..'

it should return..an array containing these 6 strings...

1.)'this is the first tym i m saying this to u..'

2.)'this is the last tym i m saying this to u..'

3.)'this is the third tym i m saying this to u..'

4.)'this is the first time i m saying this to u..'

5.)'this is the last time i m saying this to u..'

6.)'this is the third time i m saying this to u..'

Here {[ and ]} are special tags in which words are placed..seperated by |

thx

waiting 4 ur replies...:-)

[font="Comic Sans MS"][size="7"]Piyush.....[/size][/font][font="Palatino Linotype"][size="2"]Some Of My Scripts...Cool Font Generator Train Searcher and Tracer[/size][/font]

Link to comment
Share on other sites

  • Developers

waiting 4 ur replies...:-)

Understand that, like me, English isn't your mother tongue, but I am sure you can do better then this.

So, try making normal sentences in stead of this turbo talk stuff and try to be more clear in your definition of your problem and your actual question. There is no question mark in your post at all.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Understand that, like me, English isn't your mother tongue, but I am sure you can do better then this.

So, try making normal sentences in stead of this turbo talk stuff and try to be more clear in your definition of your problem and your actual question. There is no question mark in your post at all.

Jos

are you telling me to not to use the shortcuts i have used in the post for e.g. 'your' instead of 'ur'?

And i tried to explain my problem..as much as i could..i don't know wht to add to it..:-(

[font="Comic Sans MS"][size="7"]Piyush.....[/size][/font][font="Palatino Linotype"][size="2"]Some Of My Scripts...Cool Font Generator Train Searcher and Tracer[/size][/font]

Link to comment
Share on other sites

lk @ StringRegExp in t' help file

( you've got to know how to speak to these dudes :) )

Reminds me of the movie Airplane! ;)

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

Having proved to myself this method was possible, I might as well post it.

#include <Array.au3>

Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declare

Local $iCount = 0, $aResult[2000]
Local $sStr = "This is the {[first|last|third]} {[occasion|time]} I'm saying this to {[you|him|her]}."

_StringOptions($sStr, $aResult, $iCount)

If $iCount > 0 Then
    ReDim $aResult[$iCount]
    _ArrayDisplay($aResult)
EndIf


Func _StringOptions($sStr, ByRef $aResult, ByRef $iCount)
    If StringRegExp($sStr, "\{\[(.+?)\]\}") Then ; Check if "{[" and "]}" is present in string.
        Local $aArray = StringRegExp($sStr, "\{\[(.+?)\]\}", 1)
        Local $aTemp = StringSplit($aArray[0], "|", 3)
        For $j = 0 To UBound($aTemp) - 1
            Local $sTemp = StringReplace($sStr, "{[" & $aArray[0] & "]}", $aTemp[$j])
            If StringRegExp($sTemp, "\{\[(.+?)\]\}") Then ; Check if "{[" and "]}" is present in string.
                _StringOptions($sTemp, $aResult, $iCount) ; Call function again if present.
            Else
                $aResult[$iCount] = $sTemp ; Results stored in ByRef array.
                $iCount += 1
            EndIf
        Next
    EndIf
    Return
EndFunc   ;==>_StringOptions

Edit: Added ByRef variables instead of using global variables. See Varian's next post for original post.

Edited by Malkey
Link to comment
Share on other sites

Having proved to myself this method was possible, I might as well post it.

#include <Array.au3>

Global $iCount = 0, $aResult[2000]
Local $sStr = "This is the {[first|last|third]} {[occasion|time]} I'm saying this to {[you|him|her]}."

_StringOptions($sStr)

If $iCount > 0 Then
    ReDim $aResult[$iCount]
    _ArrayDisplay($aResult)
EndIf


Func _StringOptions($sStr)
    If StringRegExp($sStr, "\{\[(.+?)\]\}") Then ; Check if "{[" and "]}" is present in string.
        Local $aArray = StringRegExp($sStr, "\{\[(.+?)\]\}", 1)
        Local $aTemp = StringSplit($aArray[0], "|", 3)
        For $j = 0 To UBound($aTemp) - 1
            $sTemp = StringReplace($sStr, "{[" & $aArray[0] & "]}", $aTemp[$j])
            If StringRegExp($sTemp, "\{\[(.+?)\]\}") Then ; Check if "{[" and "]}" is present in string.
                _StringOptions($sTemp) ; Call function again if present.
            Else
                $aResult[$iCount] = $sTemp ; Results stored in global array.
                $iCount += 1
            EndIf
        Next
    EndIf
    Return
EndFunc   ;==>_StringOptions

Bravo!
Link to comment
Share on other sites

thx a lot guys for the solution....haven't tested your code..yet because i am in college....and i don't have a laptop...:idiot:

i also wrote a function during these days..in my notebook...during my classes...;)....to perform this task....

i will certainly have a look at this...again...thanks...:)

[font="Comic Sans MS"][size="7"]Piyush.....[/size][/font][font="Palatino Linotype"][size="2"]Some Of My Scripts...Cool Font Generator Train Searcher and Tracer[/size][/font]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...