zsKengren Posted December 11, 2010 Posted December 11, 2010 I am having troubles finding a character within a string The string for an example is - Intel® Core2Duo CPU T5800 @2.00GHz I am trying to delete everything after the "@" or even better yet, save the end of the string to another variable (without the @) Thanks for the Help zsKengren
kaotkbliss Posted December 11, 2010 Posted December 11, 2010 (edited) $test="Intel® Core™2Duo CPU T5800 @2.00GHz" $right=StringInStr($test,"@") $trimleft=StringTrimLeft($test,Int($right)) MsgBox(0,"",$trimleft) MsgBox(0,"",$right) *edit* the variable $right tells you how many characters in the @ symbol is after cutting off the first number of characters as returned by $right, what is left is only what is after the @ as displayed by $trimleft it should be very easy to get the script to define the $test variable with whatever data you need. Edited December 11, 2010 by kaotkbliss 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy!
Realm Posted December 11, 2010 Posted December 11, 2010 (edited) Hello zsKengren,First, Welcome to the AutoIt Forums I have a couple ideas for you, the second option is a bit rough, and I am sure there is a better way, however this should give you an idea to get started:$string = 'Intel® Core™2Duo CPU T5800 @2.00GHz' ;If you know its going to be exactly @2.00GHz $new_String = StringTrimRight($string,9) MsgBox(0,'String Is:',$new_String) ;If you need to find the @ symbol, and remove it and everything after it. $char_count = 0 While 1 If StringLeft(StringTrimLeft($string,$char_count),1) = '@' Then $new_string = StringLeft($string,$char_count) ExitLoop EndIf $char_count += 1 WEnd MsgBox(0,'String Is:',$new_String)RealmEdit: Kaotkbliss' example is a cleaner approach to my second example which does the same thing. I knew there was a better way, However I did'nt see his while our posts crossed. Edited December 11, 2010 by Realm My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.
Raik Posted December 11, 2010 Posted December 11, 2010 (edited) $x=StringSplit('Intel® Core™2Duo CPU T5800 @2.00GHz','@',2) $part1=$x[0] $part2=$x[1] ;--------------------------------- $x=StringRegExp('Intel® Core™2Duo CPU T5800 @2.00GHz',"(.*?)@(.*)",1) $part1=$x[0] $part2=$x[1] Edited December 11, 2010 by Raik AutoIt-Syntaxsheme for Proton & Phase5 * Firefox Addons by me (resizable Textarea 0.1d) (docked JS-Console 0.1.1)
zsKengren Posted December 11, 2010 Author Posted December 11, 2010 Thanks for the info, you both helped a lot!
meomeo192 Posted July 20, 2012 Posted July 20, 2012 (edited) I have this string: StringInStr Checks if a string contains a given substring. StringInStr ( "string", "substring" [, casesense [, occurrence [, start [, count]]]] ) Parameters string The string to evaluate. substring The substring to search for. casesense [optional] Flag to indicate if the operations should be case sensitive. 0 = not case sensitive, using the user's locale (default) 1 = case sensitive 2 = not case sensitive, using a basic/faster comparison occurrence [optional] Which occurrence of the substring to find in the string. Use a negative occurrence to search from the right side. The default value is 1 (finds first occurrence). start [optional] The starting position of the search. count [optional] The number of characters to search. This effectively limits the search to a portion of the full string. See remarks. I want to separate the substring between "0 = not case sensitive" and "using a basic/faster comparison ", that is this section: 0 = not case sensitive, using the user's locale (default) 1 = case sensitive 2 = not case sensitive, using a basic/faster comparison I used this code to find "0 = not case sensitive" but don't success: ;save first string in file.txt Global $x, $file $file=FileOpen("file.txt", 0) $x=StringInStr($file, "0 = not case sensitive") MsgBox(0,"1",$x) Please help me. Thank all very much. Edited July 20, 2012 by meomeo192
BrewManNH Posted July 20, 2012 Posted July 20, 2012 (edited) Try this. Global $x, $file $file=FileOpen("file.txt", 0) Global $Text = FileRead($file) $x=StringInStr($Text, "0 = not case sensitive") MsgBox(0,"1",$x) EDIT: Unicode and forum tags don't mix. Edited July 20, 2012 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
meomeo192 Posted July 20, 2012 Posted July 20, 2012 It work, thank you very much. Can you give me the code to separate the substring between "0 = not case sensitive" and "using a basic/faster comparison " ?
BrewManNH Posted July 20, 2012 Posted July 20, 2012 Look up _StringBetween If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
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