Is there a way to combine "contains" and "Startswith"? Or a better way???

I have a script that looks for reserved words in a list of words.  It works but it's slow and I think there has got to be a better and faster way.  I was thinking of how to combine the use of the -contains and $string.StartsWith but haven't had
any luck.
Here's what I have.  Any help would be appreciated.
function ProcessStartsWith ($word)
    $flag = $false
    if ($word.StartsWith("con.")) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("con,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("prn."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("prn,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("nul."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("nul,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("aux."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("aux,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("com0."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("com0,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("com1."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("com1,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("com2."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("com2,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("com3."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("com3,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("com4."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("com4,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("com5."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("com5,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("com6."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("com6,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("com7."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("com7,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("com8."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("com8,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("com9."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("com9,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("lpt0."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("lpt0,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("lpt1."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("lpt1,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("lpt2."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("lpt2,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("lpt3."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("lpt3,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("lpt4."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("lpt4,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("lpt5."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("lpt5,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("lpt6."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("lpt6,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("lpt7."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("lpt7,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("lpt8."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("lpt8,"))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("lpt9."))) { $flag = $true }
    if ((!$flag) -and ($word.StartsWith("lpt9,"))) { $flag = $true }
    return $flag
function ProcessWords($words)
    $errorcount = 0
    foreach ($word in $words)
        if (($ReservedWords -contains $word) -or (ProcessStartsWith($word)))
            "ReservedWord--- = " + $word
            $errorcount = $errorcount + 1
    return $errorcount
$ReservedWords = "prn","nul","con","aux"
$ReservedWords = $Reservedwords + "com0","com1","com2","com3","com4","com5","com6","com7","com8","com9"
$ReservedWords = $Reservedwords + "lpt0","lpt1","lpt2","lpt3","lpt4","lpt5","lpt6","lpt7","lpt8","lpt9"
$wordlist = "prn", "prnOK", "con", "control", "com0", "com0.", "com0otion"
ProcessWords($wordlist)
Running this results with this output
ReservedWord--- = prn
ReservedWord--- = con
ReservedWord--- = com0
ReservedWord--- = com0.
4

I don't know what the fastest way of accomplishing this would be, but you can certainly make it a lot shorter with a regular expression. For example, this code produces the same output:
$reservedPattern = '^(?:prn|nul|con|aux|com\d|lpt\d)(?:[\.,]|$)'
$wordlist = "prn", "prnOK", "con", "control", "com0", "com0.", "com0otion"
$matchesReserved = $wordlist -match $reservedPattern
foreach ($word in $matchesReserved)
"ReservedWord--- = $word"
$matchesReserved.Count

Similar Messages

  • Is there any BAPI which combines web and SAP??

    Is there any BAPI which combines web and SAP??

    Hi Krishna,
    <b>Good .. check the following documentation
    BAPIs are technically nothing else but RFC-enabled function modules meaning that they provide us with external access to the SAP system.
    However, BAPIs are more than "normal" RFC-enables function modules in that they generally access SAP business objects (like customer, sales order, etc.).
    Usually, a BAPI corresponds to a certain dialog transaction dealing with a SAP business object (e.g. BAPI_USER_CREATE -> SU01 to create SAP users).
    In web terms RFC is similar to HTTP and BAPIs are CGI applications.
    RFC will normally provide sy-subrc 0 or >0. Most of the BAPIS will provide a return-structure.
    RFC and BAPIs are remote enabled function modules. They are practicly the same. A BAPI is one step further as it usually is a self contained business function, such as "Create Purchase Order", or "Change Sales Document". BAPIs interface is very well defined and documented. BAPIs can be found in the BAPI browser via transaction BAPI. RFCs are just remote enabled function modules.
    refer links,
    http://searchsap.techtarget.com/ateQuestionNResponse/0,289625,sid21_cid558752_tax293481,00.html
    http://www.sap-img.com/abap/interview-question-on-bapi-rfc-abap-objects-tables.htm
    http://www.sap-img.com/fu033.htm
    http://www.sap-img.com/abap/ale-bapi.htm</b>
    Good Luck and thanks
    AK

  • Is there a way of combining From and To columns in Mail?

    I've just tumbled to the fact that Mail displays separate From and To columns--rather than an integrated Who or Correspondent one.
    In Thunderbird, with the add on Show InOut, or in the venerable Eudora, by default, there is a single column that shows you who the correspondent was and neatly italcizes your sent messages, so you can tell at a glance whether it was something you sent to the person or something they sent you.
    It's bizarre having to look back and forth at From and To to figure that out rather than scanning down a single column.  Having to display both columns also takes up needless room!
    Is there any way in Mail of combining those columns so that it works like Eudora or Thunderbird with its addon?
    Does Mail have an add on systems or take extensions?

    No application can change how the built in Contacts app works, or the Contacts list within Phone. To access your contacts, you'd need to use a third-party app that pulls the data from your contact info and shows it differently.
    But I don't know if there is one that offers the layout you describe--search and compare screenshots. Sometimes I find it easier to browse this website than the App Store in iTunes:
    http://appshopper.com/search/?search=contacts
    Maybe this one?
    http://appshopper.com/social-networking/pokemian
    For changes to the built-in apps, you'd need to ask Apple:
    http://apple.com/feedback

  • Is there a way to combine accounts and music libraries?

    My wife and I got married last year and she has and itunes account and I have one. Is there a way to deactivate her account so that I can take all her music and put it on my computer so that we have one itunes account and library to sync both our ipods to?
    Thanks,
    dp

    06scooby,
    Welcome to the Forums. Congratulations on getting married, I hope you the best. As for Combining iTunes "accounts" I don't believe it is possible. You could stop using one of the accounts for future purchases in order to make it easier and smoother. Also note you can activate up to 5 computers per account, meaning you could activate your computer to play your wife's music. I've found that you can move over music in a couple of ways. ex. you could use an external drive copy the music on it and then onto your computer. You could also setup a small network and move it over the network. Or if your up to it move all the iTunes purchases onto your iPod and then on your computer after you've activated your wife's account. Hit transfer Purchases. Then all of her purchases will transfer to your computer. The way to activate your computer with her account goto (Store)/(Authorize Computer) from the menus
    Hope this helps.

  • Is there a way to Disable "Takes" and go back to older way of working

    In Logic 7 you could just "Create tracks and mute in cycle record" for audio recording, now we have the new take folder as standard (Logic Pro 8)
    Can we disable this function as im not keen on it?

    It sounds a bit like some kind of widespread prejudice…
    No, that's a bit of a naive statement, imo. I've just had a conversation about this on another forum.
    I'm with the OP - I wish the take folder thing could be optionally turned off so we could revert to the old pre-8 behaviour.
    I had developed a very fast and efficient workflow over years - for example, while a vocalist was recording takes in cycle mode, I would be splitting, colouring, muting, naming, selecting and rejecting phrases as we went.
    This is much faster than doing a bunch of takes, and then comping them afterwards.
    Unfortunately, this is now no longer possible in LP8, as you cannot do a "create and mute tracks in cycle record" as you could do before (this option still exists in LP8 for MIDI, but not for audio). At least it was, I haven't looked at it again for a while, but I seem to remember it was the case.
    Also, quick swipe comping will not let you nudge segments in time, so you have to do your comping, then move the comp to a flattened file, then split and retime when you need to do this. And you certainly cannot comp or organise your takes while recording.
    While there are some nice things about quick swipe comping, it's not a fully developed solution, and at least for me and some others, the newer workflow is *far less efficient* than how we used to do it.
    Good reasons for being able to optionally turn take folder management off.
    In fact, when people would ask for this take folder method pre-8, I was against the feature. I find having multiple "hidden" tracks on one "real" track (like how some other DAWs did it) a much inferior solution than Logic, which could have multiple tracks all on the same audio object - so everything was visible and directly editable - none of this "choose which take to play" stuff. This was (and still is) a great feature of Logic.

  • Looking for a way to combine audio and images together into movie file

    I am using JMF to make a tiny movie.
    The thing is that I've done making sequential images (.jpeg) into a .mov(quicktime) video file, but I am not sure how to add audio (in this case in a .wav file) into this .mov . Does anybody has any idea?
    Thanks.
    P.S. this is the file that I am using to generate .mov, which is an example from SUN.
    http://www.java2s.com/Open-Source/Java-Document/Graphic-Library/apollo/org/apollo/jmf/test/JpegImagesToMovie.java.htm
    Edited by: 877113 on Aug 3, 2011 6:29 PM
    Edited by: 877113 on Aug 3, 2011 6:30 PM
    Edited by: 877113 on Aug 3, 2011 6:31 PM
    Edited by: 877113 on Aug 3, 2011 6:31 PM

    877113 wrote:
    Does anybody has any idea? Merge the video track and audio track and write it to a file using a DataSink.
    Here's an example:
    http://web.archive.org/web/20080216001555/http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Merge.html

  • How do I find and use AUNetSend or better way

    Scenario:
    My main computer (G5 PPC 10.5.8) is in my basement studio. I run Logic Pro 8.0.2 and Pro Tools 8.0.1cs2 on it (DIGI 002 interface). My secondary computer (G4 PPC 10.5.8) is in one floor up in my dining room. Not much on it, really. I could install any number of different DAWS on it if I had to. The computers are networked through a router and I have Apple Remote Desktop. Controlling my G5 from my G4 is a breeze. Works great. I even have an alternate MIDI controller connected via a long USB cable running through a hole in the floor under my desk down to the G5 (old hardwood with a knot punched out, also where my ethernet cable is run).
    Problem:
    I can't monitor audio through ARD. I have Wormhole and RAX but have been unable to figure that out. I came across "AUNetSend/Receive" while googling around. But have yet to figure out where to actually get it or how to use it even if I can find it.
    All I want to be able to do is hear what I'm working on through another computer via LAN. I'm not recording or doing any serious mixing from the remote computer. For that I go downstairs. But for simple editing work, cleaning up tracks, experimenting with software instruments, composing etc. I need to be able to work upstairs so I can be more accessible to my family at certain times.
    I don't really care if it's AUNetSend or some other means. I just want to monitor audio through my network. Is running an ethernet cable directly between the two computers an option? Then what about my internet connection? Some sort of splitter to my router? Seems this shouldn't have to be necessary. Why is this so hard to figure out? Don't more people want to be able to do this?
    THANKS

    The "Notes" app.
    Have a look at the manual:
    http://manuals.info.apple.com/en_US/iphone_user_guide.pdf

  • Is there a way to combine existing animated gifs?

    I have several animated gifs that I would like to watch in a sequence (one after another). Is there a way to combine them, and if not, is there an existing program that could accomplish that?
    Thanks

    Absoluety. You'll want to open your gif files in Photoshop by going to File > Import > Video Frames to Layers...
    Then you'll select all of your frames from one gif and copy them over into the video frames of the other gif. You'll do all of this in the Animation menu in Photoshop (Window > Animation, or Window > Timeline for CS6). You can paste the frames to whichever point you want, just make sure to designate the location by clicking on the frame you'd like them to be inserted at.
    Here's a tacky, yet extremely simple video tutorial on this process

  • How to combine Submit and Commit into a single operation?

    JDev 11.1.1.6
    Is there a simple way to combine Submit and Commit or Create and Commit or Delete and Commit into a single operation without creating a custom Operation class?
    Thanks,
    PeeVee

    Have a button and in the action listener event..you should drag and drop both create & commit onto your page so that it will have the required bindings in the pagedef.
    OperationBinding createOperationBinding = ADFUtils.getOperationBindingForMethod("Create");
    createOperationBinding.execute();
    OperationBinding commitOperationBinding = ADFUtils.getOperationBindingForMethod("Commit");
    commitOperationBinding.execute();

  • Is there a way to combine the best of slideshow and tooltip widgets?

    I am trying to produce a sliding menu similar to the "Now Playing" movies listed on this website : http://themoviehouse.com/   
    where you can mouse over and a box pops up and stays up so that you can click links within the box. The catch is that I need this box to disappear when the mouse is not on it so that content behind the box is again visable.
    I have seen this on so many websites so I assume can build this in Muse.
    Obviously with tooltip the box does not stay open. With a slideshow, the box does not disappear when you are done.
    Is there a way to combine the two or is there another widget that allows me to create what I am looking for?

    Install the Apple Configurator (osx only) and it will cache the iOS update on there after it's been installed once.  From then on each device you plug-in will take the update from Apple Config without having to download it.  I have this setup on a macbook air and it saves me a lot of time.
    The updates are device specific so make sure you update one iPhone 4, one 4S, one 5, one iPad etc before heading out to sea.  I thought installing the update on an iPhone 4S will work on an iPhone 5 but the first iPhone 5 I connected needed to download.

  • Need to delete the old page number from a combined file and replace it with the new number. is there a way for me to do that using JavaScipt

    is there a way of using JS to delete the old page number (1,3,32,78) on a combined PDF and inset it with a new page numbers (1,2,3,4) Thank you

    Depends. If the page numbers can be located by their location on the page then a script can be written to redact that area, and then add new page numbers in their place (or somewhere else).

  • I apparently have 3 apple IDs, and it's making it challenging to set up iCloud. Is there a way to combine them into the one I actually use?

    I apparently have 3 apple IDs, and it's making it challenging to set up iCloud. Is there a way to combine them into the one I actually use?

    You can't combine or merge iCloud IDs, but you can migrate the iCloud data from one account to another if you wanted to move it to a different ID.

  • Is there a way in iTunes to "stich" or combine songs?  Example Journey's Anytime and Feeling That Way are always played together.  Is there a way to combine them so they are not separate songs?

    Is there a way in iTunes to "stich" or combine songs?  Example Journey's Anytime and Feeling That Way are always played together on the radio.  Or ZZ Tops Waitin' For the Bus and Jesus Just left Chicago are always played together. Is there a way to combine them so they are not separate songs?

    Not in iTunes.
    Are these ripped from a CD?
    See hhgttg27s post here
    -> https://discussions.apple.com/thread/6867148
    If not, you will need to use another application to combine them such as this script...
    -> http://dougscripts.com/itunes/itinfo/jointogether.php

  • Is there a way to combine Media Center and Nettop?

    Hi there!
    I just ordered a mini-ITX mainboard including all the necessary components to set up a file server/media center combination. Now I realized I'll hardly need my real desktop computer. So to keep my electricity bill down I guess I'll shift to the new nettop-like thing for my daily computing needs. The question arising is:
    Is there any way to have a smooth media center UI for mp3/dvd/CD playback, but also have the option of running an ordinary desktop environment for more serious stuff? I don't know anything about xbmc, mythtv and the likes. I assume something like "have the user decide from kdm whether to run xbmc or kde" would work, but this makes for some very un-seamless switching between media playback and serious stuff. Is there some better way? I'd prefer running like xbmc, cause I expect it to boot faster than kde4, but I may be wrong...
    Any ideas anybody?
    Best wishes,
    Rufus

    You can run xbmc in full-screen mode and set it to start at boot.
    I have openbox running on mine but you could just as easily use kde or gnome. When xbmc starts full-screen there is no border so you can't tell that its really just an app running over a "normal" WM/DM.   If you need to minimize it you can just hit the \ button which brings it to "windowed" mode where you can move the window, minimize it, etc.

  • Is there any way to combine Google Calendar and iCal?

    Is there any way to combine Google Calendar and iCal?

    Here's an article that should help you:
    http://support.google.com/calendar/bin/answer.py?hl=en&answer=99358

Maybe you are looking for