ScriptNoob Posted January 21, 2009 Posted January 21, 2009 I'm trying to truncate "CN=Last\, First,OU=Accounts,OU=Corporate,OU=FSGN,DC=fsgn,DC=net" I would only want the part that says "OU=Corporate" I am able to get the text into a variable, just not sure on the syntax to truncate something.
FireFox Posted January 21, 2009 Posted January 21, 2009 @ScriptNoob ; $variable = your string StringTrimLeft(StringLeft($variable, 12), 28)Not tested Cheers, FireFox.
evilertoaster Posted January 21, 2009 Posted January 21, 2009 If it's going to be the same string length each time, you could truncate it by string length. If it's going to the second OU= each time, you could do a Stringinstr() If you're always going to have the last part be "OU=FSGN,DC=fsgn,DC=net" you could use stringright() (or alternatively stringleft()) A few more examples of possible DN's would help find the best match for you...
SpookMeister Posted January 21, 2009 Posted January 21, 2009 Can what you are looking for always be described as the second instance of text that starts with 'OU=' and ends with ',' ? [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]
ScriptNoob Posted January 21, 2009 Author Posted January 21, 2009 the DN will always be the same format with OU=Corporate being in the 3rd comma set but it will not always be the same length because CN= will have different names
FireFox Posted January 21, 2009 Posted January 21, 2009 @ScriptNoob _StringBetween ? Cheers, FireFox.
ScriptNoob Posted January 21, 2009 Author Posted January 21, 2009 (edited) Thanks Fox. Edited January 21, 2009 by ScriptNoob
ScriptNoob Posted January 21, 2009 Author Posted January 21, 2009 Can what you are looking for always be described as the second instance of text that starts with 'OU=' and ends with ',' ? Yes that is correct.
TerarinK Posted January 21, 2009 Posted January 21, 2009 Why not stringsplit with the delimit as "," then you get a array with which to test this way you can get them all CN, OU and DC. You then could run this through a loop that will test each one of the these and what it equals to. CN=Last\, First,OU=Accounts,OU=Corporate,OU=FSGN,DC=fsgn,DC=net CN Last CN First OU Accounts OU Corporate OU FSGN DC fsgn DC net Else you could just stringbetween or stringinstr. Perhaps stringinstr would be better of the two here because you have some control over OU=Coporate instead of finding text between two strings You could always use regex if you want to. 0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E
FireFox Posted January 21, 2009 Posted January 21, 2009 @TerarinK StringInStr wont work because the string change like he said... Cheers, FireFox.
TerarinK Posted January 21, 2009 Posted January 21, 2009 Yes stringinstr will work because even if the string changes it will always be searching for OU=Corporate regardless to if it is place somewhere else. The only way it fails is if you have incorrect spelling or it isn't simply in the thing you are searching. That is why I said to stringsplit then based off what you got use even one, you get a much better overall effect with that and you can't also do every one a unique search 0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E
SpookMeister Posted January 21, 2009 Posted January 21, 2009 Yes that is correct. Then this should do it. $string = "CN=Last\, First,OU=Accounts,OU=Corporate,OU=FSGN,DC=fsgn,DC=net" $firstpass = StringTrimLeft($string, StringInStr($string, "OU=") + 2) ConsoleWrite($firstpass & @CRLF); just for testing $secondpass = StringTrimLeft($firstpass, StringInStr($firstpass, "OU=") + 2) ConsoleWrite($secondpass & @CRLF); just for testing $result = StringMid($secondpass, 1, StringInStr($secondpass, ",") - 1) ConsoleWrite($result & @CRLF); just for testing [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]
Valuater Posted January 21, 2009 Posted January 21, 2009 The answer was given the DN will always be the same format with OU=Corporate being in the 3rd comma set .... Lke This... $string = "CN=Last\, First,OU=Accounts,OU=Corporate,OU=FSGN,DC=fsgn,DC=net" $Split = StringSplit( $string, ",") MsgBox(4096, "tada!", $Split[3]) 8)
SpookMeister Posted January 21, 2009 Posted January 21, 2009 The answer was given Lke This... $string = "CN=Last\, First,OU=Accounts,OU=Corporate,OU=FSGN,DC=fsgn,DC=net" $Split = StringSplit( $string, ",") MsgBox(4096, "tada!", $Split[3])oÝ÷ ÛÏêº^Y¨²Ö®¶sbb33c·7G&ærÒgV÷C´4ãÔÆ7Bb3#²Âf'7BÄõSÔ66÷VçG2ÄõSÔ6÷'÷&FRÄõSÔe4tâÄD3Ög6vâÄD3ÖæWBgV÷C° ¢b33cµ7ÆBÒ7G&æu7ÆBb33c·7G&ærÂgV÷C²ÂgV÷C² ¤×6t&÷CbÂgV÷C·FFb333²gV÷C²Â7G&æuG&ÔÆVgBb33cµ7ÆE³EÒÃ2 [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]
TerarinK Posted January 21, 2009 Posted January 21, 2009 You could easily do: StringInStr("CN=Last\, First,OU=Accounts,OU=Corporate,OU=FSGN,DC=fsgn,DC=net", "OU=Corporate")oÝ÷ ÚØb³¥¬±«k¹ë-jצz{l¢Ø^*.z0ØrëyË@±ú++-®)à²bµ«¢+ØÀÌØíÍMÑÉ¥¹ôMÑÉ¥¹MÁ±¥Ð ÅÕ½Ðí 8õ1ÍÐÀäÈì°¥ÉÍб=Tõ½Õ¹Ṉ̃=Tõ ½ÉÁ½Éѱ=TõM8±õ͸±õ¹ÐÅÕ½Ðì°ÅÕ½Ðì°ÅÕ½Ðì¤)½ÈÀÌØíÍMÑÉ¥¹%¸ÀÌØíÍMÑÉ¥¹(%MÝ¥Ñ ÀÌØíÍMÑÉ¥¹($% ÍÅÕ½Ðí=Tõ ½ÉÁ½ÉÑÅÕ½Ðì($$%}½M½µÑ¡¥¹ ¤(%¹MÝ¥Ñ )9á 0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E
SpookMeister Posted January 21, 2009 Posted January 21, 2009 Doh, I misinterpreted his desired results.... using Valuaters corrected but much more elegant method it would be: $string = "CN=Last\, First,OU=Accounts,OU=Corporate,OU=FSGN,DC=fsgn,DC=net" $Split = StringSplit( $string, ",") MsgBox(4096, "tada!", $Split[4]) [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]
DangerousDan Posted January 22, 2009 Posted January 22, 2009 (edited) I've had a lot of practice with the string functions anyone do this in stringregexp yet? I quit reading when it went way over my head, does scripting experience help you understand that crap any better ? $string = "CN=Last\, First,OU=Accounts,OU=Corporate,OU=FSGN,DC=fsgn,DC=net" ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $string = ' & $string & @crlf & '>Error code: ' & @error & @crlf);### Debug Console $newstring=stringtrimright(StringTrimLeft($string,StringInStr($string,",",2,3)),(stringlen($string)-stringinstr($string,",",2,-3)+1)) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $newstring = ' & $newstring & @crlf & '>Error code: ' & @error & @crlf);### Debug Console Edited January 22, 2009 by DangerousDan
TerarinK Posted January 22, 2009 Posted January 22, 2009 Yes I have done it in a stringregexp: StringRegExp($sValue, "(?i)(\w*)=(\w*)", 4) this will result in: [0,0] = CN=Last [0,1] = CN [0,2] = Last [1,0] = OU=Accounts [1,1] = OU [1,2] = Accounts [2,0] = OU=Corporate [2,1] = OU [2,2] = Corporate [3,0] = OU=FSGN [3,1] = OU [3,2] = FSGN [4,0] = DC=fsgn [4,1] = DC [4,2] = fsgn [5,0] = DC=net [5,1] = DC [5,2] = net As you see this does bring up a bug in the " First" as I am unsure how he got that. There might be other way to accomplish this task by only one CN,OU and DC followed by the name seperated by a comma as I am sure he has done but then that leads tothe "\" that I'm unsure of. Please explain so we can get a following functioning example put up here This way you would have to create a double loop so "For To Unbound Next" follow by another one. 0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E
ScriptNoob Posted January 22, 2009 Author Posted January 22, 2009 (edited) As you see this does bring up a bug in the " First" as I am unsure how he got that. There might be other way to accomplish this task by only one CN,OU and DC followed by the name seperated by a comma as I am sure he has done but then that leads tothe "\" that I'm unsure of. Please explain so we can get a following functioning example put up here This way you would have to create a double loop so "For To Unbound Next" follow by another one.First of all I want to thank everyone for their responses to this problem, you have been most helpful and I am greatly appreciative.To answer your question the "/" is used when you don't want to include the "," as part of the Samid string.The only part I need out of it however is "OU=Corporate" in this example, which could differ from location to location but always starts with "OU=" and always is in the 3rd comma set. Edited January 22, 2009 by ScriptNoob
ScriptNoob Posted January 22, 2009 Author Posted January 22, 2009 You could easily do: StringInStr("CN=Last\, First,OU=Accounts,OU=Corporate,OU=FSGN,DC=fsgn,DC=net", "OU=Corporate")oÝ÷ ÚØb³¥¬±«k¹ë-jצz{l¢Ø^*.z0ØrëyË@±ú++-®)à²bµ«¢+ØÀÌØíÍMÑÉ¥¹ôMÑÉ¥¹MÁ±¥Ð ÅÕ½Ðí 8õ1ÍÐÀäÈì°¥ÉÍб=Tõ½Õ¹Ṉ̃=Tõ ½ÉÁ½Éѱ=TõM8±õ͸±õ¹ÐÅÕ½Ðì°ÅÕ½Ðì°ÅÕ½Ðì¤)½ÈÀÌØíÍMÑÉ¥¹%¸ÀÌØíÍMÑÉ¥¹(%MÝ¥Ñ ÀÌØíÍMÑÉ¥¹($% ÍÅÕ½Ðí=Tõ ½ÉÁ½ÉÑÅÕ½Ðì($$%}½M½µÑ¡¥¹ ¤(%¹MÝ¥Ñ )9á This would work if my string will always be "OU=Corporate", but it could be "OU=Chicago" or several other locations, im think I need to split the strings like you have done but into a case where I can always select the 3rd case....
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now