Search Results

Search found 4616 results on 185 pages for 'c strings'.

Page 18/185 | < Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >

  • help with making a password checker in java

    - by Cheesegraterr
    Hello, I am trying to make a program in Java that checks for three specific inputs. It has to be 1. At least 7 characters. 2. Contain both upper and lower case alphabetic characters. 3. Contain at least 1 digit. So far I have been able to make it check if there is 7 characters, but I am having trouble with the last two. What should I put in my loop as an if statement to check for digits and make it upper and lower case. Any help would be greatly appreciated. Here is what I have so far. import java.awt.*; import java.io.*; import java.util.StringTokenizer; public class passCheck { private static String getStrSys () { String myInput = null; //Store the String that is read in from the command line BufferedReader mySystem; //Buffer to store the input mySystem = new BufferedReader (new InputStreamReader (System.in)); //creates a connection to system input try { myInput = mySystem.readLine (); //reads in data from the console myInput = myInput.trim (); } catch (IOException e) //check { System.out.println ("IOException: " + e); return ""; } return myInput; //return the integer to the main program } //**************************************** //main instructions go here //**************************************** static public void main (String[] args) { String pass; //the words the user inputs String temp = ""; //holds temp info int stringLength; //length of string boolean goodPass = false; System.out.print ("Please enter a password: "); //ask for words pass = getStrSys (); //get words from system temp = pass.toLowerCase (); stringLength = pass.length (); //find length of eveyrthing while (goodPass == false) { if (stringLength < 7) { System.out.println ("Your password must consist of at least 7 characters"); System.out.print ("Please enter a password: "); //ask for words pass = getStrSys (); stringLength = pass.length (); goodPass = false; } else if (something to check for digits) { } }

    Read the article

  • Decoding tcp packets using python

    - by mikip
    Hello I am trying to decode data received over a tcp connection. The packets are small, no more than 100 bytes. However when there is a lot of them I receive some of the the packets joined together. Is there a way to prevent this. I am using python I have tried to separate the packets, my source is below. The packets start with STX byte and end with ETX bytes, the byte following the STX is the packet length, (packet lengths less than 5 are invalid) the checksum is the last bytes before the ETX def decode(data): while True: start = data.find(STX) if start == -1: #no stx in message pkt = '' data = '' break #stx found , next byte is the length pktlen = ord(data[1]) #check message ends in ETX (pktken -1) or checksum invalid if pktlen < 5 or data[pktlen-1] != ETX or checksum_valid(data[start:pktlen]) == False: print "Invalid Pkt" data = data[start+1:] continue else: pkt = data[start:pktlen] data = data[pktlen:] break return data , pkt I use it like this #process reports try: data = sock.recv(256) except: continue else: while data: data, pkt = decode(data) if pkt: process(pkt) Also if there are multiple packets in the data stream, is it best to return the packets as a collection of lists or just return the first packet I am not that familiar with python, only C, is this method OK. Any advice would be most appreciated. Thanks in advance Thanks

    Read the article

  • Counting longest occurence of repeated sequence in Python

    - by user248237
    What's the easiest way to count the longest consecutive repeat of a certain character in a string? For example, the longest consecutive repeat of "b" in the following string: my_str = "abcdefgfaabbbffbbbbbbfgbb" would be 6, since other consecutive repeats are shorter (3 and 2, respectively.) How can I do this in Python? thanks.

    Read the article

  • why string is a reference type?

    - by saurabh
    We know that string is a reference type , so we have string s="God is great!"; but on the same note if i declare class say Employee which is a reference type so why below piece of code does not work ? Employee e = "Saurabh"; 2- How do we actually determine if a type is a reference type or value type?

    Read the article

  • Create a string with the result of an expression and the expression that originated the value. Is it

    - by Oscar Reyes
    Like String r = SomeThing.toExecString("new Object().toString()"); And when executed the value of r would be: "new Object().toString() = java.lang.Object@c5e3974" Is this even possible at all? Would it need a bunch of reflection? A built in compiler maybe? AFAIK, this is not possible with regular Java. The closest thing I could get is IDE support like in IDEA with the "macro" soutv+tab that prints: Hit taband type the expression The IDE types the rest for you. But that's quite another completely thing.

    Read the article

  • split string error in a compiled VB.NET class

    - by Andy Payne
    I'm having some trouble compiling some VB code I wrote to split a string based on a set of predefined delimeters (comma, semicolon, colon, etc). I have successfully written some code that can be loaded inside a custom VB component (I place this code inside a VB.NET component in a plug-in called Grasshopper) and everything works fine. For instance, let's say my incoming string is "123,456". When I feed this string into the VB code I wrote, I get a new list where the first value is "123" and the second value is "456". However, I have been trying to compile this code into it's own class so I can load it inside Grasshopper separately from the standard VB component. When I try to compile this code, it isn't separating the string into a new list with two values. Instead, I get a message that says "System.String []". Do you guys see anything wrong in my compile code? You can find an screenshot image of my problem at the following link: click to see image This is the VB code for the compiled class: Public Class SplitString Inherits GH_Component Public Sub New() MyBase.New("Split String", "Split", "Splits a string based on delimeters", "FireFly", "Serial") End Sub Public Overrides ReadOnly Property ComponentGuid() As System.Guid Get Return New Guid("3205caae-03a8-409d-8778-6b0f8971df52") End Get End Property Protected Overrides ReadOnly Property Internal_Icon_24x24() As System.Drawing.Bitmap Get Return My.Resources.icon_splitstring End Get End Property Protected Overrides Sub RegisterInputParams(ByVal pManager As Grasshopper.Kernel.GH_Component.GH_InputParamManager) pManager.Register_StringParam("String", "S", "Incoming string separated by a delimeter like a comma, semi-colon, colon, or forward slash", False) End Sub Protected Overrides Sub RegisterOutputParams(ByVal pManager As Grasshopper.Kernel.GH_Component.GH_OutputParamManager) pManager.Register_StringParam("Tokenized Output", "O", "Tokenized Output") End Sub Protected Overrides Sub SolveInstance(ByVal DA As Grasshopper.Kernel.IGH_DataAccess) Dim myString As String DA.GetData(0, myString) myString = myString.Replace(",", "|") myString = myString.Replace(":", "|") myString = myString.Replace(";", "|") myString = myString.Replace("/", "|") myString = myString.Replace(")(", "|") myString = myString.Replace("(", String.Empty) myString = myString.Replace(")", String.Empty) Dim parts As String() = myString.Split("|"c) DA.SetData(0, parts) End Sub End Class This is the custom VB code I created inside Grasshopper: Private Sub RunScript(ByVal myString As String, ByRef A As Object) myString = myString.Replace(",", "|") myString = myString.Replace(":", "|") myString = myString.Replace(";", "|") myString = myString.Replace("/", "|") myString = myString.Replace(")(", "|") myString = myString.Replace("(", String.Empty) myString = myString.Replace(")", String.Empty) Dim parts As String() = myString.Split("|"c) A = parts End Sub ' ' End Class

    Read the article

  • PHP-REGEX: accented letters matches non-accented ones, and visceversa. How to achive it?

    - by Lightworker
    I want to do the typical higlight code. So I have something like: $valor = preg_replace("/(".$_REQUEST['txt_search'].")/iu", "<span style='background-color:yellow; font-weight:bold;'>\\1</span>", $valor); Now, the request word could be something like "josé". And with it, I want "jose" or "JOSÉ" or "José" or ... highlighted too. With this expression, if I write "josé", it matches "josé" and "JOSÉ" (and all the case variants). It always matches the accented variants only. If I search "jose", it matches "JOSE", "jose", "Jose"... but not the accented ones. So I've partially what I want, cause I have case insensitive on accented and non-accented separately. I need it fully combined, wich means accent (unicode) insensitive, so I can search "jose", and highlight "josé", "josÉ", "José", "JOSE", "JOSÉ", "JoSé", ... I don't want to do a replace of accents on the word, cause when I print it on screen I need to see the real word as it comes. Any ideas? Thanks!

    Read the article

  • Transposing and Untransposing a String in java

    - by Will
    I have been working on two methods that will Transpose and Untranspose a String respectively. The solutions that I have come up with both work to the best of my knowledge. I just want to know if I could have solved these problems in a simpler way. My code seems like it is too long for the task that is being performed. The first method, transpose(), will take a String as a parameter and transpose it. If "bridge" is entered, the output will be "bergid". Likewise, with the unTranspose() method, if the user enters "bergid", the output will be "bridge". public void transpose( String s ) { String t = ""; int end = s.length() - 1; for ( int i = 0; i < s.length() / 2; i++ ) { t += Character.toString( s.charAt( i ) ) + Character.toString( s.charAt( end ) ); end--; } // Lenth of String is odd if ( s.length() % 2 == 1 ) { // add character in middle of String to the end of the new String t+= Character.toString( s.charAt( s.length() / 2 ) ); } System.out.println( t ); } public void unTranspose( String s ) { String t = ""; // Length of String is odd if ( s.length() % 2 == 1 ) { for ( int i = 0; i < s.length(); i+=2 ) { t+= Character.toString( s.charAt( i ) ); } for ( int i = s.length() - 2; i > 0; i -= 2 ) { t += Character.toString( s.charAt( i ) ); } System.out.println( t ); } // Length of String is even else if ( s.length() % 2 == 0 ) { for ( int i = 0; i < s.length() - 1; i+=2 ) { t+= Character.toString( s.charAt( i ) ); } for ( int i = s.length() - 1; i > 0; i -= 2 ) { t+= Character.toString( s.charAt( i ) ); } System.out.println( t ); } } My code looks horrible. I'm still not used to formatting my code correctly. Please bear with me. Thanks for your time

    Read the article

  • problem with if statement used to determine function return

    - by Patrick
    Im using an if statement to determine what to return in a function, but it seems to be not working the way i want it to. function DoThis($dogs, $cats){ // do something with dogs, pet them perhaps. $reg = $dogs[0]; $nate = $dogs[1]; if($cats = "dave"){return $reg;} if($cats = "tom"){return $nate;} } $cats is a string (if that helps), and when entered it doesn't yield any return. If i manually set a return, that works, but the above doesnt for some reason.

    Read the article

  • strcasecmp in C returns 156 instead of 0, any ideas why?

    - by hora
    I have the following code: printf("num: %d\n", strcasecmp(buf, "h\n")); And I get the following results when I try plugging in different letters: a: -7 g: -1 i: 1 j: 2 h: 156 H: 156 Should strcasecmp not return 0 when buf is equal to H or h? Any ideas why it's returning 156? I need to figure out how to check whether the user types H or h. Thanks!

    Read the article

  • VB.net Insert Environment.NewLine at 20 characters.

    - by xzerox
    Well I have been able to figure this out but what I want to do is make my string have a new line after 20 chars. I know how to find how many chars the string has but not how to insert environment.newline at 20 chars. I am using this to find the string length If string.Length > 20 then 'Need to be able to insert environment.newline at 20 chars Else 'Normal string End If

    Read the article

  • How can I determine a file extension given a file path in LaTeX?

    - by Frank
    I am attempting to write a LaTeX package which leverages the minted package's \inputminted command. My \mycommand command takes two parameters, the first being a path to a file, and I want to pass the file's extension to the \inputminted command: \newcommand\mycommand[2]{ \inputminted{#1}{...} } Note that the above won't work since the full path is passed to \inputminted. Example: \mycommand{/path/to/Test.java}{blah} should invoke \inputminted{java}{...}

    Read the article

  • Optimal method to create a large string containing several variables?

    - by Runcible
    I want to create a string that contains many variables: std::string name1 = "Frank"; std::string name2 = "Joe"; std::string name3 = "Nancy"; std::string name4 = "Sherlock"; std::string sentence; sentence = name1 + " and " + name2 + " sat down with " + name3; sentence += " to play cards, while " + name4 + " played the violin."; This should produce a sentence that reads Frank and Joe sat down with Nancy to play cards, while Sherlock played the violin. My question is: What is the optimal way to accomplish this? I am concerned that constantly using the + operator is ineffecient. Is there a better way?

    Read the article

  • Simple way to repeat a String in java

    - by e5
    I'm looking for a simple commons method or operator that allows me to repeat some String n times. I know I could write this using a for loop, but I wish to avoid for loops whenever necessary and a simple direct method should exist somewhere. String str = "abc"; String repeated = str.repeat(3); repeated.equals("abcabcabc"); Related to: repeat string javascript Create NSString by repeating another string a given number of times Edited I try to avoid for loops when they are not completely necessary because: They add to the number of lines of code even if they are tucked away in another function. Someone reading my code has to figure out what I am doing in that for loop. Even if it is commented and has meaningful variables names, they still have to make sure it is not doing anything "clever". Programmers love to put clever things in for loops, even if I write it to "only do what it is intended to do", that does not preclude someone coming along and adding some additional clever "fix". They are very often easy to get wrong. For loops that involving indexes tend to generate off by one bugs. For loops often reuse the same variables, increasing the chance of really hard to find scoping bugs. For loops increase the number of places a bug hunter has to look.

    Read the article

  • Help with Arrays in Objective C.

    - by NJTechie
    Problem : Take an integer as input and print out number equivalents of each number from input. I hacked my thoughts to work in this case but I know it is not an efficient solution. For instance : 110 Should give the following o/p : one one zero Could someone throw light on effective usage of Arrays for this problem? #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int input, i=0, j,k, checkit; int temp[i]; NSLog(@"Enter an integer :"); scanf("%d", &input); checkit = input; while(input > 0) { temp[i] = input%10; input = input/10; i++; } if(checkit != 0) { for(j=i-1;j>=0;j--) { //NSLog(@" %d", temp[j]); k = temp[j]; //NSLog(@" %d", k); switch (k) { case 0: NSLog(@"zero"); break; case 1: NSLog(@"one"); break; case 2: NSLog(@"two"); break; case 3: NSLog(@"three"); break; case 4: NSLog(@"four"); break; case 5: NSLog(@"five"); break; case 6: NSLog(@"six"); break; case 7: NSLog(@"seven"); break; case 8: NSLog(@"eight"); break; case 9: NSLog(@"nine"); break; default: break; } } } else NSLog(@"zero"); [pool drain]; return 0; }

    Read the article

  • PHP String tokenizer not working correctly

    - by asdadas
    I have no clue why strtok decided to break on me. Here is my code. I am tokenizing a string by dollar symbol $. echo 'Tokenizing this by $: ',$aliases,PHP_EOL; if(strlen($aliases) > 0) { //aliases check $token = strtok($aliases, '$'); while($token != NULL) { echo 'Found a token: ',$token,PHP_EOL; if(!isGoodLookup($token)) { echo 'ERROR: Invalid alias found.',PHP_EOL; stop($db); } $goodAliasesList[] = $token; $token = strtok('$'); } if($token == NULL) echo 'Found null token, moving on',PHP_EOL; } And this is my output: Tokenizing this by $: getaways$aaa Found a token: getaways Found null token, moving on str tok is not supposed to do this!! where is my aaa token!!

    Read the article

  • How to regex match a string of alnums and hyphens, but which doesn't begin or end with a hyphen?

    - by Shahar Evron
    I have some code validating a string of 1 to 32 characters, which may contain only alpha-numerics and hyphens ('-') but may not begin or end with a hyphen. I'm using PCRE regular expressions & PHP (albeit the PHP part is not really important in this case). Right now the pseudo-code looks like this: if (match("/^[\p{L}0-9][\p{L}0-9-]{0,31}$/u", string) and not match("/-$/", string)) print "success!" That is, I'm checking first that the string is of right contents, doesn't being with a '-' and is of the right length, and then I'm running another test to see that it doesn't end with a '-'. Any suggestions on merging this into a single PCRE regular expression? I've tried using look-ahead / look-behind assertions but couldn't get it to work.

    Read the article

  • How to convert CFStringRef to NSString?

    - by papr
    NSString *aNSString; CFStringRef aCFString; aCFString = CFStringCreateWithCString(NULL, [aNSString UTF8String], NSUTF8StringEncoding); aCFString = CFXMLCreateStringByUnescapingEntities(NULL, aCFString, NULL); How can I get a new NSString from aCFString?

    Read the article

< Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >