Switch with Regex

Hi,
I'm having some trouble replicating this powershell code in C# could anyone give me a hand or point me in the right direction?
Powershell:
$FirstLetter = $Promoter.Substring(0,1)
Switch -Regex ($FirstLetter)
"[A-G]" {"A - J"}
"[K-Z]" {"K - Z"}
If this is helpful please mark it so. Also if this solved your problem mark as answer.

Hi TenPart,
I am glad to know you solved this problem and thanks for sharing the solution.
It will be very beneficial for other community members who have the similar questions. Thanks.
Best regards,
Kristin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.

Similar Messages

  • Find Replace from Textfile with regex

    Hello.
    I'm wondering if anyone knows about an existing script that does a find/replace by list like the script "FindChangeByList.jsx" that comes with every InDesign installation.
    This consists of tow parts, the script itself with the functionality and a simple textfile where you have simple one-liners capable of find/replace with regex.
    the Textfile:
    //FindChangeList.txt
    //A support file for the InDesign CS4 JavaScript FindChangeByList.jsx
    //This data file is tab-delimited, with carriage returns separating records.
    //The format of each record in the file is:
    //findType<tab>findProperties<tab>changeProperties<tab>findChangeOptions<tab>description
    //Where:
    //<tab> is a tab character
    //findType is "text", "grep", or "glyph" (this sets the type of find/change operation to use).
    //findProperties is a properties record (as text) of the find preferences.
    //changeProperties is a properties record (as text) of the change preferences.
    //findChangeOptions is a properties record (as text) of the find/change options.
    //description is a description of the find/change operation
    //Very simple example:
    //text          {findWhat:"--"}          {changeTo:"^_"}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all double dashes and replace with an em dash.
    //More complex example:
    //text          {findWhat:"^9^9.^9^9"}          {appliedCharacterStyle:"price"}          {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}          Find $10.00 to $99.99 and apply the character style "price".
    //All InDesign search metacharacters are allowed in the "findWhat" and "changeTo" properties for findTextPreferences and changeTextPreferences.
    //If you enter backslashes in the findWhat property of the findGrepPreferences object, they must be "escaped"
    //as shown in the example below:
    //{findWhat:"\\s+"}
    grep          {findWhat:"  +"}          {changeTo:" "}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all double spaces and replace with single spaces.
    grep          {findWhat:"\r "}          {changeTo:"\r"}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all returns followed by a space And replace with single returns.
    grep          {findWhat:" \r"}          {changeTo:"\r"}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all returns followed by a space and replace with single returns.
    grep          {findWhat:"\t\t+"}          {changeTo:"\t"}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all double tab characters and replace with single tab characters.
    grep          {findWhat:"\r\t"}          {changeTo:"\r"}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all returns followed by a tab character and replace with single returns.
    grep          {findWhat:"\t\r"}          {changeTo:"\r"}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all returns followed by a tab character and replace with single returns.
    grep          {findWhat:"\r\r+"}          {changeTo:"\r"}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all double returns and replace with single returns.
    text          {findWhat:" - "}          {changeTo:"^="}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all space-dash-space and replace with an en dash.
    text          {findWhat:"--"}          {changeTo:"^_"}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all dash-dash and replace with an em dash.
    The script:
    //FindChangeByList.jsx
    //An InDesign CS5.5 JavaScript
    @@@BUILDINFO@@@ "FindChangeByList.jsx" 3.0.0 15 December 2009
    //Loads a series of tab-delimited strings from a text file, then performs a series
    //of find/change operations based on the strings read from the file.
    //The data file is tab-delimited, with carriage returns separating records.
    //The format of each record in the file is:
    //findType<tab>findProperties<tab>changeProperties<tab>findChangeOptions<tab>description
    //Where:
    //<tab> is a tab character
    //findType is "text", "grep", or "glyph" (this sets the type of find/change operation to use).
    //findProperties is a properties record (as text) of the find preferences.
    //changeProperties is a properties record (as text) of the change preferences.
    //findChangeOptions is a properties record (as text) of the find/change options.
    //description is a description of the find/change operation
    //Very simple example:
    //text          {findWhat:"--"}          {changeTo:"^_"}          {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}          Find all double dashes and replace with an em dash.
    //More complex example:
    //text          {findWhat:"^9^9.^9^9"}          {appliedCharacterStyle:"price"}          {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}          Find $10.00 to $99.99 and apply the character style "price".
    //All InDesign search metacharacters are allowed in the "findWhat" and "changeTo" properties for findTextPreferences and changeTextPreferences.
    //If you enter backslashes in the findWhat property of the findGrepPreferences object, they must be "escaped"
    //as shown in the example below:
    //{findWhat:"\\s+"}
    //For more on InDesign scripting, go to http://www.adobe.com/products/indesign/scripting/index.html
    //or visit the InDesign Scripting User to User forum at http://www.adobeforums.com
    main();
    function main(){
              var myObject;
              //Make certain that user interaction (display of dialogs, etc.) is turned on.
              app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
              if(app.documents.length > 0){
                        if(app.selection.length > 0){
                                  switch(app.selection[0].constructor.name){
                                            case "InsertionPoint":
                                            case "Character":
                                            case "Word":
                                            case "TextStyleRange":
                                            case "Line":
                                            case "Paragraph":
                                            case "TextColumn":
                                            case "Text":
                                            case "Cell":
                                            case "Column":
                                            case "Row":
                                            case "Table":
                                                      myDisplayDialog();
                                                      break;
                                            default:
                                                      //Something was selected, but it wasn't a text object, so search the document.
                                                      myFindChangeByList(app.documents.item(0));
                        else{
                                  //Nothing was selected, so simply search the document.
                                  myFindChangeByList(app.documents.item(0));
              else{
                        alert("No documents are open. Please open a document and try again.");
    function myDisplayDialog(){
              var myObject;
              var myDialog = app.dialogs.add({name:"FindChangeByList"});
              with(myDialog.dialogColumns.add()){
                        with(dialogRows.add()){
                                  with(dialogColumns.add()){
                                            staticTexts.add({staticLabel:"Search Range:"});
                                  var myRangeButtons = radiobuttonGroups.add();
                                  with(myRangeButtons){
                                            radiobuttonControls.add({staticLabel:"Document", checkedState:true});
                                            radiobuttonControls.add({staticLabel:"Selected Story"});
                                            if(app.selection[0].contents != ""){
                                                      radiobuttonControls.add({staticLabel:"Selection", checkedState:true});
              var myResult = myDialog.show();
              if(myResult == true){
                        switch(myRangeButtons.selectedButton){
                                  case 0:
                                            myObject = app.documents.item(0);
                                            break;
                                  case 1:
                                            myObject = app.selection[0].parentStory;
                                            break;
                                  case 2:
                                            myObject = app.selection[0];
                                            break;
                        myDialog.destroy();
                        myFindChangeByList(myObject);
              else{
                        myDialog.destroy();
    function myFindChangeByList(myObject){
              var myScriptFileName, myFindChangeFile, myFindChangeFileName, myScriptFile, myResult;
              var myFindChangeArray, myFindPreferences, myChangePreferences, myFindLimit, myStory;
              var myStartCharacter, myEndCharacter;
              var myFindChangeFile = myFindFile("/FindChangeSupport/FindChangeList.txt")
              if(myFindChangeFile != null){
                        myFindChangeFile = File(myFindChangeFile);
                        var myResult = myFindChangeFile.open("r", undefined, undefined);
                        if(myResult == true){
                                  //Loop through the find/change operations.
                                  do{
                                            myLine = myFindChangeFile.readln();
                                            //Ignore comment lines and blank lines.
                                            if((myLine.substring(0,4)=="text")||(myLine.substring(0,4)=="grep")|| (myLine.substring(0,5)=="glyph")){
                                                      myFindChangeArray = myLine.split("\t");
                                                      //The first field in the line is the findType string.
                                                      myFindType = myFindChangeArray[0];
                                                      //The second field in the line is the FindPreferences string.
                                                      myFindPreferences = myFindChangeArray[1];
                                                      //The second field in the line is the ChangePreferences string.
                                                      myChangePreferences = myFindChangeArray[2];
                                                      //The fourth field is the range--used only by text find/change.
                                                      myFindChangeOptions = myFindChangeArray[3];
                                                      switch(myFindType){
                                                                case "text":
                                                                          myFindText(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
                                                                          break;
                                                                case "grep":
                                                                          myFindGrep(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
                                                                          break;
                                                                case "glyph":
                                                                          myFindGlyph(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);
                                                                          break;
                                  } while(myFindChangeFile.eof == false);
                                  myFindChangeFile.close();
    function myFindText(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
              //Reset the find/change preferences before each search.
              app.changeTextPreferences = NothingEnum.nothing;
              app.findTextPreferences = NothingEnum.nothing;
              var myString = "app.findTextPreferences.properties = "+ myFindPreferences + ";";
              myString += "app.changeTextPreferences.properties = " + myChangePreferences + ";";
              myString += "app.findChangeTextOptions.properties = " + myFindChangeOptions + ";";
              app.doScript(myString, ScriptLanguage.javascript);
              myFoundItems = myObject.changeText();
              //Reset the find/change preferences after each search.
              app.changeTextPreferences = NothingEnum.nothing;
              app.findTextPreferences = NothingEnum.nothing;
    function myFindGrep(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
              //Reset the find/change grep preferences before each search.
              app.changeGrepPreferences = NothingEnum.nothing;
              app.findGrepPreferences = NothingEnum.nothing;
              var myString = "app.findGrepPreferences.properties = "+ myFindPreferences + ";";
              myString += "app.changeGrepPreferences.properties = " + myChangePreferences + ";";
              myString += "app.findChangeGrepOptions.properties = " + myFindChangeOptions + ";";
              app.doScript(myString, ScriptLanguage.javascript);
              var myFoundItems = myObject.changeGrep();
              //Reset the find/change grep preferences after each search.
              app.changeGrepPreferences = NothingEnum.nothing;
              app.findGrepPreferences = NothingEnum.nothing;
    function myFindGlyph(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){
              //Reset the find/change glyph preferences before each search.
              app.changeGlyphPreferences = NothingEnum.nothing;
              app.findGlyphPreferences = NothingEnum.nothing;
              var myString = "app.findGlyphPreferences.properties = "+ myFindPreferences + ";";
              myString += "app.changeGlyphPreferences.properties = " + myChangePreferences + ";";
              myString += "app.findChangeGlyphOptions.properties = " + myFindChangeOptions + ";";
              app.doScript(myString, ScriptLanguage.javascript);
              var myFoundItems = myObject.changeGlyph();
              //Reset the find/change glyph preferences after each search.
              app.changeGlyphPreferences = NothingEnum.nothing;
              app.findGlyphPreferences = NothingEnum.nothing;
    function myFindFile(myFilePath){
              var myScriptFile = myGetScriptPath();
              var myScriptFile = File(myScriptFile);
              var myScriptFolder = myScriptFile.path;
              myFilePath = myScriptFolder + myFilePath;
              if(File(myFilePath).exists == false){
                        //Display a dialog.
                        myFilePath = File.openDialog("Choose the file containing your find/change list");
              return myFilePath;
    function myGetScriptPath(){
              try{
                        myFile = app.activeScript;
              catch(myError){
                        myFile = myError.fileName;
              return myFile;
    This is a very useful and easy to maintain script which even people who cant write scripts (but know how to use regex) can do complex search replace mass replacements.
    Would love to find something like this for FrameMaker 12 (as i can't write scripts myself).
    regards
    daniel

    I have visited that site. The first item in the external link says: "You can also configure Firefox to automatically search for text when you type any characters outside of a text field. When typing in a text field these characters should show up in the text field and not trigger the Quick Find bar. "
    What I am looking for is the exact opposite. Once my first search is entered in the text box, and the info comes back, I want to start typing the next symbol, and have it automatically show up in the text box, not the Quick Find box. That is how it was working up until a couple of months ago.

  • Using Catalyst 3550 Switch with Linksys Home Router and Cable Internet

    I've about pulled what little hair I have out of my head on this one, and need some configuration help.
    I have a Cisco Catalyst 3550 switch with five Windows 7 desktops, an Avaya PBX and five Avaya IP phones attached.  All of these devices are on a 192.168.0.0/24 subnet, and are communicating properly.  I will refer to this as network # 1. I also have SEPARATE network, we'll call network # 2, using AT&T ADSL service and a Netgear 4-port/wireless router/ADSL modem combo device, which is functioning properly with a couple of other Windows 7 desktops over its own wired Ethernet network, using DHCP, and also on a 192.168.0.0/24 subnet.  I thought it would be a simple integration, just plugging one of the 3550's ports to one of the DSL router's ports, in order to give the five Windows 7 desktop computers on network # 1 internet access via the DSL modem. Guess I was wrong.  When I connect the two switches together, although I get a good connectivity (green lights on both ports) and am able to ping the DSL router's gateway address (192.168.0.252) from network # 1's computers, the computers on network # 1 cannot access the internet. Also, the working computers on network # 2 lose their internet access as long as the two switches are connected together. I am not a Cisco guru, but there's got to be a way to make this scenario work.  Can someone provide me with a 3550 configuration that will allow me to extend my internet service from network # 2 on the DSL router to my 3550 switch and their computers?  Here's what I am looking for:
    INTERNET ---> ADSL MODEM ---> NETGEAR ROUTER ---> CISCO 3550 SWITCH ---> NETWORK DEVICES WITH INTERNET ACCESS

    The Netgear router is probably what's doing the natting. Is the 3550 configured for routing or is it straight L2? If you have the 3550 configured as L3, then it's going to be easy to do what you want. Just add a static route on the Netgear to point the subnet that it doesn't know about to the 3550. For example, if the Netgear is addressed at 192.168.1.1 and the Cisco 3550 is addressed at 192.168.1.2, but it also knows about the 192.168.0.0/24 (separate vlan), then you would put a static route on your Netgear for 192.168.0.0/24 to go to 192.168.1.2.
    The way that I would do it is to create a separate vlan on the 3550 and assign an address to it. Once you do that, make the port that the other switch connects to an access port of that vlan. (It would need to be on the same subnet as the existing equipment.) All of your devices would use it as a default gateway and then you would do the rest as above. You could also use RIP between the Netgear and Cisco if you can't do static routing.
    HTH,
    John

  • After installing an update I am no longer able to hear sound out of my speakers. A red light comes on where the headphone jack is. I have already attempted to trip to switch with a wooden toothpick in the headphone jack but have not had luck.

    after installing an update I am no longer able to hear sound out of my speakers. A red light comes on where the headphone jack is. I have already attempted to trip to switch with a wooden toothpick in the headphone jack but have not had luck.

    Have you gone into system prefs nad made sure that the headphone port is set to audio out. And not audio in.
    Also make sure that you are selecting built in speakers for your audio output.
    If that does not fix it try doing a Pram reset.
    Shut your mac down.
    Press the startup button.
    Hold down the following keys. Command Option P and R. Wait till you hear the chime 2 times. Then let go. See if that fixes it.

  • Toggle switches with if else

    I am trying to toggle various switches based off of others and am wondering how I can go about this. For example, if switch A is on, B should toggle off. If I toggle B on, A should toggle off. Any help in doing this would be appreciated. Thanks.

    Thank you for an easy question..... 
    There's a mode in the Switch options that allows you to create a single switch with two channels, where only one will be on.
    - cj
    Measurement Computing (MCC) has free technical support. Visit www.mccdaq.com and click on the "Support" tab for all support options, including DASYLab.

  • Change a 3560 Switch with Lifetime Waranty

    A simple question:
    Our client has 3560X Switches with a limited lifetime warranty. The Cisco Partner with whom they had the contract before bought the equipment, and they did not end up on good terms. One of the devices died the other day. My question is - how do we replace it now?
    Thanks

    I wish... here is the answer I got from TAC: "in this case there is nothing we can do to replace it as per Cisco policies and procedures customer has to engage his reseller for support."
    So disappointing... Now I need to call the client and tell them they need to throw the lifetime warranty switch away and buy a new one... 

  • HDMI switching with YV box - help?

    I am now in the unfortunate position of having a TV with only one HDMI input but currently have two boxes (YouView and NowTV) that output HDMI. The one scart input is used by the DVD player and I'm aware of scart-switch problems where YV boxes are concerned too.
    I bought a Duronics HDMI auto-switcher, it has three inputs and one output. I connected it up and the NowTV box displayed its bouncing logo fine. I switched on the YV box and got a pink screen. I tried unplugging the NowTV box from the mains, unplugging the HDMI lead etc. Cycling through the inputs using the manual switch - still the same pink screen, turned box on-off etc.
    Has anyone managed to use a HDMI switcher and if so how or which one and if it does work, does it always work without a problem? 
    For info: I have a BT supplied box (the first one they sent out, Humax ..), power set to the quicker starting one (eco-mode: Low??)

    I use a Thor combined HDMI/Optical switch with the YV box with no problem. Occasionally see a flash of pink when it switches then it settles down.
    Does this happen if you switch first before turning on the YV box (does your auto-switcher let you manually override to do this)?
    Have you re-tried plugging the HDMI lead direct into the TV as it maybe just a co-incidence this started happening when you introduced the switch?
    One other thing I suggest you try is swapping the HDMI leads between the YV box and the Now TV device.

  • Operating a SG200-08 switch with case removed.

    I am going to be putting an SG200-08 (8 port switch) inside a 2U rackmount chassis.
    To enhance cooling I thought I would remove the outer case.
    Are there, or would there be any issues with using the switch with the cover removed?
    Thanks
    Glen

    Hi Glen, the first issue would be, the warranty is void and you're not entitled to any support. The second issue would be static electricity and environmental concerns. The third issue would likely be your property insurance.
    It is highly against recommendation to alter or modify these units.
    -Tom
    Please mark answered for helpful posts

  • Two Switches with same MAC+Priority running STP

    Hi
    what will happen if two switch with same MAC-ADDRESS and same STP priority will run STP , how will elect to the root bridge ???? how the STP process will handle this situation?
    thanx

    Well, first off, no two switches (or switchports) will have the same MAC (if they do, you're buying switches from the wrong, very bad place).
    Every port of the switch will have (at least) one MAC of it's own.
    Given the same priority for all switches/bridges on the LAN, the lowest switch/bridge MAC on the LAN will win as the root.
    VLANS take on the MAC of the administrative interface ("CPU"): i.e., xxxx.xxxx.5000, the first port (i.e., fa0/1) is xxxx.xxxx.5001, the second (fa0/2) is xxx.xxxx.5002, and so on
    If you do a "show interface", the MAC / bia is displayed in the second line.
    Good Luck
    Scott

  • Limit switches with MID-7604

    I am trying to integrate a forward and reverse limit switch with a linear actuator. I need the actuator to find the forward limit, offset from the switch enough the disengage the switch, stop there while another task is occuring, then retract to the reverse limit, and finally offset from the reverse switch enough to disengage the switch.
    I'm able to get this procedure to work one time through when the driver is just turned on, but after it's gone through the procedure more than once, the actuators no longer offset. I'm defining the offset amount in Measurement and Automation Explorer. It appears that the "find reference" VI longer finds the forward and reverse limits after the first time because if I probe the output of the "check reference" VI, the value is false even when the actuator has stopped on the limit switch.
    Is there something I need to clear after each cycle? Any suggestions would be great. 

    Hello,
    Do you have any data acquisition board? You will need one to capture the signal and process in labview.
    If you don´t have one, you can search in NI website. The NI has several models.
    Best regards.

  • Can we have 3 way vertical toggle switch, with unstable position at top, neutral position in center and stable position at bottom. the shape of the switch should be same as that of vertical toggle switch.

    can we have 3 way vertical toggle switch, with unstable position at top, neutral position in center and stable position at bottom. the shape of the switch should be same as that of vertical toggle switch.

    Avon,
    You've asked the same question and received several replies in two recent threads here and here.
    Rather than start a third thread, it would be best to just respond in one of them with details as to your problems with the proposed solutions (e.g. use of picture control).
    =====================================================
    Fading out. " ... J. Arthur Rank on gong."

  • ACE HTTP Probe with regex

    ACE HTTP Probe with regex
    Hi,
    I'm trying to setup a HTTP probe with expected string rather then a code (config below). I do a GET for the page then a search for a string in the response however it's not working, as probe appears as failed.
    I've tested the connection to the server by using telneting and then looking at the page displayed to make sure the string I want to match is in the response.
    probe http HTTP-PROBE
    port 43050
    interval 30
    passdetect interval 30
    passdetect count 1
    request method get url /action=help
    open 43050
    expect regex action=help
    Q. Is there anything wrong with this configuration and what I'm trying to achive?
    Thanks,
    Pritesh

    Use "expect status" under probe config. expect regex doesnt work if expect status is not configured.
    expect regex work flawlessly with static pages. It doesnt work all the time with dynamic pages.
    Specially if "content-length" header is missing from Server response.
    Hope it helps
    Syed Iftekhar Ahmed

  • Can I Stack Switches with differents Part Numbers? Is it possible??

    Hi,
    I have a doubt, I need to buy 4 Switches Cisco 3750-X, but 2 with UTP/RJ-45 Ports, and 2 with STP capability.
    My question is, for example, Can I stack 2 WS-C3750X-48T-E and 2 WS-C3750X-24S-E??

    Disclaimer
    The Author of this posting offers the information contained within this posting without consideration and with the reader's understanding that there's no implied or expressed suitability or fitness for any purpose. Information provided is for informational purposes only and should not be construed as rendering professional advice of any kind. Usage of this posting's information is solely at reader's own risk.
    Liability Disclaimer
    In no event shall Author be liable for any damages whatsoever (including, without limitation, damages for loss of use, data or profit) arising out of the use or inability to use the posting's information even if Author has been advised of the possibility of such damage.
    Posting
    The only limitation of stacking different 3750X models is the feature set of the installed IOS.
    I.e.:  "The Cisco Catalyst 3750-X Series Switches with LAN Base feature set can only stack with other Cisco Catalyst 3750‑X Series LAN Base switches. A mixed stack of LAN Base switch with IP Base or IP Services features set is not supported."

  • Problem with regex

    sorry about my english.
    i'm working with large xml file which it data like this
    (this is sample data)
    <DOCTYPE lewis SYSTEM "lewis.dtd">
    <REUTERS TOPICS="NO" LEWISSPLIT="TEST" CGISPLIT="TRAINING-SET" OLDID="20436" NEWID="21001">
    <DATE>19-OCT-1987 15:37:46.03</DATE>
    <TOPICS></TOPICS>
    <PLACES></PLACES>
    <PEOPLE></PEOPLE>
    <ORGS></ORGS>
    <EXCHANGES></EXCHANGES>
    <COMPANIES></COMPANIES>
    <UNKNOWN>
    F
    f2882reute
    f f BC-CITYFED-FINANCI   10-19 0013</UNKNOWN>
    <TEXT TYPE="BRIEF">
    ******<TITLE>CITYFED FINANCIAL CORP SAYS IT CUT QTRLY DIVIDEND TO ONE CENT FROM 10 CTS/SHR
    </TITLE>Blah blah blah.
    </TEXT>
    </REUTERS>
    <REUTERS TOPICS="YES" LEWISSPLIT="TEST" CGISPLIT="TRAINING-SET" OLDID="20435" NEWID="21002">
    <DATE>19-OCT-1987 15:35:53.55</DATE>
    <TOPICS><D>crude</D><D>ship</D></TOPICS>
    <PLACES><D>bahrain</D><D>iran</D><D>usa</D></PLACES>
    <PEOPLE></PEOPLE>
    <ORGS></ORGS>
    <EXCHANGES></EXCHANGES>
    <COMPANIES></COMPANIES>
    <UNKNOWN>
    2873reute
    r f AM-GULF-PLATFORM   10-19 0101</UNKNOWN>
    <TEXT>
    <TITLE>HUGE OIL PLATFORMS DOT GULF LIKE BEACONS</TITLE>
    <AUTHOR>    By ASHRAF FOUAD</AUTHOR>
    <DATELINE>    BAHRAIN, Oct 19 - </DATELINE><BODY>Blah blah blah
    </BODY></TEXT>
    </REUTERS>
    <REUTERS TOPICS="YES" LEWISSPLIT="TEST" CGISPLIT="TRAINING-SET" OLDID="20435" NEWID="21002">
    <DATE>19-OCT-1987 15:35:53.55</DATE>
    <TOPICS><D>ship</D></TOPICS>
    <PLACES><D>bahrain</D><D>iran</D><D>usa</D></PLACES>
    <PEOPLE></PEOPLE>
    <ORGS></ORGS>
    <EXCHANGES></EXCHANGES>
    <COMPANIES></COMPANIES>
    <UNKNOWN>
    Y
    f2873reute
    r f AM-GULF-PLATFORM   10-19 0101</UNKNOWN>
    <TEXT>
    <TITLE>LIKE BEACONS</TITLE>
    <AUTHOR>    By ASHRAF FOUAD</AUTHOR>
    <DATELINE>    BAHRAIN, Oct 19 - </DATELINE><BODY>Blah blah blah
    </BODY></TEXT>
    </REUTERS>
    <REUTERS TOPICS="YES" LEWISSPLIT="TEST" CGISPLIT="TRAINING-SET" OLDID="20435" NEWID="21002">
    <DATE>19-OCT-1987 15:35:53.55</DATE>
    <TOPICS><D>ship</D></TOPICS>
    <PLACES><D>bahrain</D><D>iran</D><D>usa</D></PLACES>
    <PEOPLE></PEOPLE>
    <ORGS></ORGS>
    <EXCHANGES></EXCHANGES>
    <COMPANIES></COMPANIES>
    <UNKNOWN>
    Y
    f2873reute
    r f AM-GULF-PLATFORM   10-19 0101</UNKNOWN>
    <TEXT>
    <TITLE>HUGE OIL PLATFORMS DOT GULF LIKE BEACONS</TITLE>
    <AUTHOR>    By ASHRAF FOUAD</AUTHOR>
    <DATELINE>    BAHRAIN, Oct 19 - </DATELINE><BODY>Blah blah blah
    </BODY></TEXT>
    </REUTERS>
    <REUTERS TOPICS="YES" LEWISSPLIT="TEST" CGISPLIT="TRAINING-SET" OLDID="20435" NEWID="21002">
    <DATE>19-OCT-1987 15:35:53.55</DATE>
    <TOPICS><D>ship</D></TOPICS>
    <PLACES></PLACES>
    <PEOPLE></PEOPLE>
    <ORGS></ORGS>
    <EXCHANGES></EXCHANGES>
    <COMPANIES></COMPANIES>
    <UNKNOWN>
    Y
    f2873reute
    r f AM-GULF-PLATFORM   10-19 0101</UNKNOWN>
    <TEXT>
    <TITLE>HUGE OIL PLATFORMS DOT GULF LIKE BEACONS</TITLE>
    <AUTHOR>    By ASHRAF FOUAD</AUTHOR>
    <DATELINE>    BAHRAIN, Oct 19 - </DATELINE><BODY>Blah blah blah
    </BODY></TEXT>
    </REUTERS>i'm try to remove article with no topic or two or more topic.
    this is my code.(sorry for not clean the code many testing in it)
    package reuterxmlextraction;
    import java.io.*;
    import java.util.ArrayList;
    import java.util.regex.Pattern;
        public static void main(String[] args) throws IOException {
            int traningcount = 0;
            int testingcount = 0;
            int notopicex = 0;
            int multitopicex = 0;
            int totaltest = 0;
            int totaltrain = 0;
            int countarticle = 0;
            String finalOutput = "";
            File rfile = new File(args[0]);
            try {
                // Open the file that is the first
                // command line parameter
                FileInputStream fstream = new FileInputStream(rfile);
                // Get the object of DataInputStream
                DataInputStream in = new DataInputStream(fstream);
                BufferedReader br = new BufferedReader(new InputStreamReader(in), 1024 * 100);
                String strLine;
                String preOutput = "";
                ArrayList<String> preOutputmod = new ArrayList<String>();
                //Read File Line By Line
                //           while ((strLine = br.readLine()) != null) {
                //preOutput += strLine;
                //System.out.print(strLine);
                int len = (int) (rfile.length());
                byte buf[] = new byte[len];
                fstream.read(buf);
                fstream.close();
                preOutput = new String(buf);
                //System.out.println(preOutput);
                totaltest = count(preOutput, "LEWISSPLIT=\"TEST\"");
                totaltrain = count(preOutput, "LEWISSPLIT=\"TRAIN\"");
                int tempindex = 0;
                while (preOutput.indexOf("<REUTERS ", tempindex) != -1) {
                    //        while(tempindex == 0){
                    int a = preOutput.indexOf("<REUTERS ", tempindex);
                    //System.out.print(a +"\n");
                    int b = preOutput.indexOf("</REUTERS>", tempindex) + 10;
                    //System.out.print(b +"\n");
                    char pre[] = new char[b - a];
                    preOutput.getChars(a, b, pre, 0);
                    preOutputmod.add(String.valueOf(pre));
                    tempindex = b;
                    countarticle++;
                int loop = 0;
                while (loop < preOutputmod.size()) {
                    if (preOutputmod.get(loop).matches(".+<TOPICS>\\s*</TOPICS>.+")) {
                        preOutputmod.remove(loop);
                        notopicex++;
                        continue;
                    if (Pattern.matches(".+[<TOPICS>]?[<D>.+</D>]{2,}</TOPICS>.+\\s*", preOutputmod.get(loop))) {
                        preOutputmod.remove(loop);
                        multitopicex++;
                        continue;
                    } else {
                        finalOutput += preOutputmod.get(loop);
                    loop++;
            } catch (Exception e) {//Catch exception if any
                System.err.println("Error: " + e.getMessage());
            if (args[1] != null) {
                File f = new File(args[1]);
                Writer output = new BufferedWriter(new FileWriter(f));
                try {
                    //FileWriter always assumes default encoding is OK!
                    output.write(finalOutput);
                } finally {
                    output.close();
        static int count(String base, String searchFor) {
            int len = searchFor.length();
            int result = 0;
            if (len > 0) {  // search only if there is something
                int start = base.indexOf(searchFor);
                while (start != -1) {
                    result++;
                    start =
                            base.indexOf(searchFor, start + len);
            return result;
    }problem is that regex in my code don't work.
    i'm not good with regex.
    please help.
    ps.the xml i mentioned is reuter-21578 dataset total size approx 27mb

    Just saying "doesn't work" is meaningless. You need to provide details about exactly what went wrong.
    However, that's irrelevant here, since this is NOT a good job for regex. Use an XML parser.

  • The # keys on macbook switched with leters below it.

    A friend's Macbook number keys are switched with the letter key below it (pressing 1 shows a Q).  She says it happened on its own and no one messed with it.  It's a few years old, not sure on specs and OS beyond that. I'm thinking its a simple software fix and not a hardware problem. Any suggestions?

    Connect the iPod to your computer and restore via iTunes. See:
    iTunes: Backing up, updating, and restoring iOS software

Maybe you are looking for

  • How do I print from my iPad to a USB printer on my time capsule?

    I have a Mac mini, iPad 2, iPad 3rd gen, 2 iPhone 5's, and a 2TB time capsule. All running the latest versions of their respective OS's. The hp printer I got at apple is plugged into the USB port on the time capsule because I couldn't figure out how

  • How to process (populate & merge) XFA PDF Forms using Adobe library in Java

    We have the XFA Forms (.pdf) created in Adobe LiveCycle designer 8.2 ES. We have the following requirement : 1. We need to populate data in those forms using standalone Java programs. 2. We need to merge the populated forms and create a single PDF ou

  • Apple Mail Acting Up

    Hi everyone, I just got my new macbook air three weeks ago and since then been going crazy with this issue. I added my gmail account to apple mail and it's been acting up ever since. At times it won't connect to the SMTP server (out going messages) a

  • Restore Accidentally deleted songs

    I accidentally deleted a whole Genre and many songs, rather then delete one duplicate song, which is what i wanted. Most songs not from ITUNEs store but from disks, whihc i no longer have. As a result, i've deleted many fav. songs. I cannot find in I

  • No Sound on R3D files in AE

    I have some R3D files here from my Red Scarlet and Epic. I used the A Box from wooden camera and a microfone with xlr to record sound direct on footage. In Redcine X and Premiere i got the waveform and the sound, but in After Effects i got only a dea