Search Results

Search found 35302 results on 1413 pages for 'string literals'.

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

  • string parsing occurrence in c

    - by Dan74
    I have a string as const char *str = "Hello, this is an example of my string"; How could I get everything after the first comma. So for this instance: this is an example of my string I was planing to do something like: // pseudocode char *a, *b; loop { if((a = strchr(l, ',')) == NULL) break; b++; // but not sure here } printf("%s",a); Thanks

    Read the article

  • Application leaking Strings?

    - by Jörg B.
    My .net application does some heavy string loading/manipulation and unfortunately the memory consumption keeps rising and rising and when looking at it with a profiler I see alot of unreleased string instances. Now at one point of time or another I do need all objects t hat do have these string fields, but once done, I could get rid of e.g. the half of it and I Dispose() and set the instances to null, but the Garbage Collector does not to pick that up.. they remain in memory (even after half an hour after disposing etc). Now how do I get properly rid of unneeded strings/object instances in order to release them? They are nowhere referenced anymore (afaik) but e.g. aspose's memory profiler says their distance to the gc's root is '3'?

    Read the article

  • gdb: SIGTRAP on std::string::c_str() call

    - by sheepsimulator
    So I've been trying to use gdb to return the value of a string I have by calling > print <member variable name>.c_str() But everytime I do so, I get this: Program received signal SIGTRAP, Trace/breakpoint trap. <some address> in std::string::c_str() from /usr/lib/libstdc++.so.6 GDB remains in the frame where the signal was received. To change this behavior use "set unwindonsignal on" Evaluation of the expression containing the function (std::string::c_str() const) will be abandoned. Two questions: Why/how is the standard library throwing SIGTRAP? I checked basic_string.h and c_str() is defined as: const _CharT* c_str() const { return _M_data(); } I don't see any SIGTRAP-throwing here... is there a way to get around this SIGTRAP? How can I read the text value of the std::string out (without getting some crazy extension library) in gdb?

    Read the article

  • [C] Signed Hexadecimal string to long int function

    - by Ben
    I am trying to convert a 24bit Hexadecimal string (6 characters) signed in two's complement to a long int in C. This is the function I have come up with: long int hex2li (char string[]) { char *pEnd; long int result = strtol (string, &pEnd, 16); if (strcmp (pEnd, "") == 0) { if (toupper (string[0]) == 'F') { return result - 16777216; } else { return result; } } return LONG_MIN; } Is it valid? Is there a better way of doing this?

    Read the article

  • Convert string to integer and multiply two integers

    - by demlasjr
    I have a big time trying to either convert a string into a integer or multiply two integers. I can't convert the string into integer because it's resulting me into a boolean (when I'm using var_dump). I can convert the other integer in string, but I'm unable to multiply it. I have this: <? $fees=$commerce->cart->get_total(); $payfee = str_replace('&nbsp;&euro;', '', $fees); $payfee = str_replace(',','', $payfee); //this is the string $fee = 0.025; $paypal = $payfee * $fee; //this thing is not working ?> I tried converting the payfee in integer, but still can't make it work. I did something like this before and worked well, but not this time. Any help will be appreciated. P.S Thank you to the whole stackoverflow.com community which helped me many times before.

    Read the article

  • How to get a Clean String in Javascript?

    - by streetparade
    i have a long String. With some German characters and lots of new lines tabs ect.. In a Selectbox user can select a text, on change i do document.getElementById('text').value=this.value; But this fails. I just get a "unterminated string literal" as error in JavaScript. I think i should clean the string. How can i do it in JavaScript?

    Read the article

  • how does fgets internally works?

    - by Registered User
    Well it is a basic question but I seem confused enough. #include<stdio.h> int main() { char a[100]; printf("Enter a string\n"); scanf("%s",a); } Basically the above is what I want to achieve. If I enter a string James Bond then I want that to be stored in array a. But the problem is because of presence of a blank space in between only James word is stored. So how can I solve this one. UPDATE After the replies given below I understand fgets() would be a better choice. I want to know internal working of fgets as why is it able to store the string with space where as scanf is not able to do the same.

    Read the article

  • String concatenation produces incorrect output in Python?

    - by Brian
    I have this code: filenames=["file1","FILE2","file3","fiLe4"] def alignfilenames(): #build a string that can be used to add labels to the R variables. #format goal: suffixes=c(".fileA",".fileB") filestring='suffixes=c(".' for filename in filenames: filestring=filestring+str(filename)+'",".' print filestring[:-3] #now delete the extra characters filestring=filestring[-1:-4] filestring=filestring+')' print "New String" print str(filestring) alignfilenames() I'm trying to get the string variable to look like this format: suffixes=c(".fileA",".fileB".....) but adding on the final parenthesis is not working. When I run this code as is, I get: suffixes=c(".file1",".FILE2",".file3",".fiLe4" New String ) Any idea what's going on or how to fix it?

    Read the article

  • regular expression for string in c

    - by darkie15
    Hi All, I am working writing a regular expression used to validate string in C. Here is to what I have gone so far '^"[A-Za-z0-9]*[\t\n]*"$' for rules - A string should begin with double quotes - May not contain a newline character However, I am not able to capture the rule for allowing '\' or '"' in a string if preceded with '\'. Here is what I tried: '^"[A-Za-z0-9]*[\t\n]*[\\\|\\"]?"$' But this doesn't seem to work. What might be wrong with the regular expression here? Regards, darkie15

    Read the article

  • Efficient way in Python to add an element to a comma-separated string

    - by ensnare
    I'm looking for the most efficient way to add an element to a comma-separated string while maintaining alphabetical order for the words: For example: string = 'Apples, Bananas, Grapes, Oranges' addition = 'Cherries' result = 'Apples, Bananas, Cherries, Grapes, Oranges' Also, a way to do this but while maintaining IDs: string = '1:Apples, 4:Bananas, 6:Grapes, 23:Oranges' addition = '62:Cherries' result = '1:Apples, 4:Bananas, 62:Cherries, 6:Grapes, 23:Oranges' Sample code is greatly appreciated. Thank you so much.

    Read the article

  • Regex string match?

    - by Andy
    I have a long string in javascript like var string = 'abc234832748374asdf7943278934haskhjdasfhjkdfas83421def8923487234897234897'; I am trying to match like abc234832748374 and def8923487234897 - that is - I have tried like string.match(\abc[^abc]|\def[^def]|) but that doesnt get me both strings because I need numbers after them ? Basically I need abc + 8 chars after and def the 8-11 chars after ? How can I do this ?

    Read the article

  • Oracle database connection string PLSQL compatibility

    - by user521180
    Hi I'm using an application called Logi info. it requires a connection string to my oracle database. the connection works fine but in order to configure the connection to recive ref cursors from the database, I apparently need to add PLSQLRSet=1 to the end of the string. when I do that I recieve an error "invalid connection string" Here is my connection string without plsqlrset=1 Data Source=SID; User Id=username; Password=password; My concern is that PLSQLRSet=1 might be .NET paramater only. Can anyone shed some light on the issue. Thanks

    Read the article

  • C Check Substring of a String C

    - by user69514
    I'm trying to check whether or not the second argument in my program is a substring of the first argument. The problem is that it only work if the substring starts with the same letter of the string. EDIT: It must be done in C, not C++. Sorry #include <stdio.h> #include <string.h> int my_strstr( char const *s, char const *sub ) { char const *ret = sub; while ( ret = strchr( ret, *sub ) ) { if ( strcmp( ++ret, sub+1 ) == 0 ) return 1; } return 0; } int main(int argc, char **argv){ if (argc != 3) { printf ("Usage: check <string one> <string two>\n"); } int result = my_strstr(argv[1], argv[2]); if(result == 1){ printf("%s is a substring of %s\n", argv[2], argv[1]); } else{ printf("%s is not a substring of %s\n", argv[2], argv[1]); } return 0; }

    Read the article

  • Using IF statements to find string length in array for alignment (Visual Basic)

    - by Brodoin
    My question is just as it says in the title. How would one use IF statements to find the string-length of content in an array, and then make it so that they show up in a Rich Text Box with the left sides aligned? Noting that one value in my array is a Decimal. Imports System.IO Imports System.Convert Public Class frmAll 'Declare Streamreader Private objReader As StreamReader 'Declare arrays to hold the information Private strNumber(24) As String Private strName(24) As String Private strSize(24) As String Private decCost(24) As Integer Private Sub frmAll_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Set objReader objReader = New StreamReader("products.csv") 'Call the FillArray sub to fill the array Call FillArray() End Sub Private Sub FillArray() 'Declare variables and arrays Dim decCost(24, 1) As Decimal Dim strFields() As String Dim strRec As String Dim intCount As Integer = 0 Dim chrdelim As Char = ToChar(",") 'Set strRec to read the lines strRec = objReader.ReadLine 'Do while loop to fill array. Do While strRec <> Nothing strFields = strRec.Split(chrdelim) strNumber(intCount) = strFields(0) strName(intCount) = strFields(1) strSize(intCount) = strFields(2) decCost(intCount, 0) = ToDecimal(strFields(3)) decCost(intCount, 1) = ToDecimal(strFields(4)) 'Set strRec to read the lines again strRec = objReader.ReadLine 'increment the index intCount += 1 Loop 'Call the Calculate sub for calculation Call Calculate(decCost) End Sub Private Sub Calculate(ByVal numIn(,) As Decimal) 'Define arrays to hold total cost Dim decRowTotal(24) As Decimal 'Define variables to hold the counters for rows and columns Dim intR As Integer Dim intC As Integer 'Calcualte total cost For intC = 0 To 1 For intR = 0 To 24 decRowTotal(intR) += numIn(intR, intC) * 1 Next Next 'Call the Output sub to configure the output. Call Output(numIn, decRowTotal) End Sub Private Sub Output(ByVal NumIn(,) As Decimal, _ ByVal RowTotalIn() As Decimal) 'Variables Dim strOut As String Dim intR As Integer = 0 Dim intC As Integer = 0 'Set header for output. strOut = "ID" & vbTab & "Item" & vbTab & vbTab & vbTab & "Size" & _ vbTab & vbTab & vbTab & vbTab & "Total Price" & _ vbCrLf & "---------- ... -------------------------" & vbCrLf 'For loop to add each line to strOut, setting 'the RowTotalIn to currency. For intC = 0 To 24 strOut &= strNumber(intC) & vbTab strOut &= strName(intC) & vbTab strOut &= strSize(intC) & vbTab strOut &= RowTotalIn(intC).ToString("c") & vbCrLf Next 'Add strOut to rbtAll rtbAll.Text = strOut End Sub End Class Output It shows up with vbTabs in my output, but still, it looks similar in that they are not aligned. The first two do, but after that they are not, and I am totally lost. P0001 Coffee - Colombian Supreme 24/Case: Pre-Ground 1.75 Oz Bags $16.50 P0002 Coffee - Hazelnut 24/Case: Pre-Ground 1.75 Oz Bags $24.00 P0003 Coffee - Mild Blend 24/Case: Pre-Ground 1.75 Oz Bags $20.50 P0004 Coffee - Assorted Flavors 18/Case. Pre-Ground 1.75 Oz Bags $23.50 P0005 Coffee - Decaf 24/Case: Pre-Ground 1.75 Oz Bags $20.50

    Read the article

  • Converting an empty string into nil in Ruby

    - by adi92
    I have a string called word and a function called infinitive such that word.infinitive would return another string on some occasions and an empty string otherwise I am trying to find an elegant ruby one line expression for the code-snippet below if word.infinitive == "" return word else return word.infinitive Had infinitive returned nil instead of "", I could have done something like (word.infinitive or word) But since it does not, I can't take advantage of the short-circuit OR Ideally I would want 1) a single expression that I could easily embed in other code 2) the function infinitive being called only once 3) to not add any custom gems or plugins into my code

    Read the article

  • Finding ALL positions of a substring in a large string in C#

    - by Tommy
    Alright, so what i have, is a large string i need to parse, and what i need to happen, is find all the instances of extract"(me,i-have lots. of]punctuation, and store them to a list. So say this piece of string was in the beginning and middle of the larger string, both of them would be found, and their index's would be added to the List. and the List would contain 0 and the other index whatever it would be. Ive been playing around, and the string.IndexOf does almost what i'm looking for, and ive written some code. But i cant seem to get it to work: List<int> inst = new List<int>(); int index = 0; while (index < source.LastIndexOf("extract\"(me,i-have lots. of]punctuation", 0) + 39) { int src = source.IndexOf("extract\"(me,i-have lots. of]punctuation", index); inst.Add(src); index = src + 40; } inst = The list source = The large string Any better ideas?

    Read the article

  • StringBuffer wont read whole stream into a string (JAVA/Android)

    - by Levara
    Hi all! I'm making an android program that retrieves content of a webpage using HttpURLConnection. I'm new to both Java and Android. Problem is: Reader reads whole page source, but in the last while iteration it doesn't append to stringBuffer that last part. Using debbuger I have determined that, in the last loop iteration, string buff is created, but stringBuffer just doesnt append it. I need to parse retrieved content. Is there any better way to handle the content for parsing than using strings. I've read on numerous other sites that string size in Java is limited only by available heap size. I've tried with StringBuilder too. Anyone know what could be the problem. Btw feel free to suggest any improvements to the code. Thanks! URL u; try { u = new URL("http://feeds.timesonline.co.uk/c/32313/f/440134/index.rss"); HttpURLConnection c = (HttpURLConnection) u.openConnection(); c.setRequestProperty("User-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727)"); c.setRequestMethod("GET"); c.setDoOutput(true); c.setReadTimeout(3000); c.connect(); StringBuffer stringBuffer = new StringBuffer(""); InputStream in = c.getInputStream(); InputStreamReader inp = new InputStreamReader(in); BufferedReader reader = new BufferedReader(inp); char[] buffer = new char[3072]; int len1 = 0; while ( (len1 = reader.read(buffer)) != -1 ) { String buff = new String(buffer,0,len1); stringBuffer.append(buff); } String stranica = new String(stringBuffer); c.disconnect(); reader.close(); inp.close(); in.close();

    Read the article

  • Get index of nth occurrence of char in a string

    - by StickFigs
    I'm trying to make a function that returns the index of the Nth occurrence of a given char in a string. Here is my attempt: private int IndexOfNth(string str, char c, int n) { int index = str.IndexOf(c) + 1; if (index >= 0) { string temp = str.Substring(index, str.Length - index); for (int j = 1; j < n; j++) { index = temp.IndexOf(c) + 1; if (index < 0) { return -1; } temp = temp.Substring(index, temp.Length - index); } index = index + (str.Length); } return index; } This should find the first occurrence, chop off that front part of the string, find the first occurrence from the new substring, and on and on until it gets the index of the nth occurrence. However I failed to consider how the index of the final substring is going to be offset from the original actual index in the original string. How do I make this work? Also as a side question, if I want the char to be the tab character do I pass this function '\t' or what?

    Read the article

  • How can I manually interpolate string escapes in a Perl string?

    - by Ryan Thompson
    In perl suppose I have a string like 'hello\tworld\n', and what I want is: 'hello world ' That is, "hello", then a literal tab character, then "world", then a literal newline. Or equivalently, "hello\tworld\n" (note the double quotes). In other words, is there a function for taking a string with escape sequences and returning an equivalent string with all the escape sequences interpolated?

    Read the article

  • Find and replace text in a string using C#

    - by Joey Morani
    Anyone know how I would find & replace text in a string? Basically I have two strings: string firstS = "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABQODxIPDRQSERIXFhQYHzMhHxwcHz8tLyUzSkFOTUlBSEZSXHZkUldvWEZIZoxob3p9hIWET2ORm4+AmnaBhH//2wBDARYXFx8bHzwhITx/VEhUf39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f3//"; string secondS = "abcdefg2wBDABQODxIPDRQSERIXFh/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/abcdefg"; I want to search firstS to see if it contains any sequence of characters that's in secondS and then replace it. It also needs to be replaced with the number of replaced characters in squared brackets: [NUMBER-OF-CHARACTERS-REPLACED] For example, because firstS and secondS both contain "2wBDABQODxIPDRQSERIXFh" and "/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/f39/" they would need to be replaced. So then firstS becomes: string firstS = "/9j/4AAQSkZJRgABAQEAYABgAAD/[22]QYHzMhHxwcHz8tLyUzSkFOTUlBSEZSXHZkUldvWEZIZoxob3p9hIWET2ORm4+AmnaBhH//2wBDARYXFx8bHzwhITx/VEhUf39[61]f3//"; Hope that makes sense. I think I could do this with Regex, but I don't like the inefficiency of it. Does anyone know of another, faster way?

    Read the article

  • Property value of a String object in JavaScript

    - by naivists
    As far as I understand, every string is an object in Javascript. Still, it "does not work" as I expect it to be: var a="abc"; //here we get a new string object a.b = 123; //I seem to declare a property "b" of that object alert(a.b); //alerts "undefined" However, if I try to define a string in the "wrong way", everything works as expected var a=new String("abc"); // a.b = 123; alert(a.b); //alerts "123" Why is that so?

    Read the article

  • passing string literal to std::map::find(..)

    - by ra170
    I've got a std::map. I'm passing string literal to find method. Obviously, I can pass a string literal such as .find("blah"); However, I wanted to declare it upfront, instead of hardcoding the string, so I have couple of choices now: const std::string mystring = "blah"; const char mystring[] = "blah"; static const char * mystring = "blah"; They all work. (or at least compile). My question is, which one should I use? what's the advantage/distavantage over of the other?

    Read the article

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