w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Oracle SQL SUBSTR function
You can use rtrim() function, specifying as a second parameter character(s) that you want to remove from the right-hand side of a string: SQL> with t1(Last_name, First_name) as( 2 select 'aaaa', 'bbb -' from dual union all 3 select 'aaa', 'bbbb -' from dual union all 4 select 'aaa', 'gggg j' from dual 5 ) 6 select last_name 7 , rtrim(first_name, ' -') as first_name 8 from t1 9 ; Result: LAST_NAME FIRST_NAME --------- ---------- aaaa bbb aaa bbbb aaa gggg j Starting from Oracle 10g version, you could also use regexp_replace() regular expression function: select last_name , regexp_replace(first_name, 's*-s*$') as first_name from t1 Result: LAST_NAME FIRST_NAME --------- ---------- aaaa bbb aaa bbbb aaa

Categories : SQL

substr() function for array PHP
you can use array_walk: function fcn(&$item) { $item = substr(..do what you want here ...); } array_walk($matches, "fcn");

Categories : PHP

foo.substr gives "Is not a function" error
var foo = $("#textDatepicker").datepicker('getDate'); returns a Date object, not a string, and has no method substr() FIDDLE You can solve it by removing that unsightly inline event handler and doing : $("#textDatepicker").datepicker({ onSelect: function() { var date = $(this).datepicker('getDate'); var day = $.datepicker.formatDate('DD', date); $('#dayofweek').html(day); } }); FIDDLE

Categories : Javascript

My function dont transmit substr c++
You are trying to bind a temporary, returned by std::string::substr, to a non-const reference. You cannot do that, but you can bind to a const reference: void Object::actionsFace(const std::string &line, int &iteration_face); This will pass a reference to the temporary string, but you cannot modify it inside of the function. Alternatively, you can explicitly make a copy, as with test in your example. Alternatively, if you need a local copy of the string inside your function only, you can pass by value: void Object::actionsFace(std::string line, int &iteration_face);

Categories : C++

How to write substr function in active record class of codeigniter model?
Try it like this: $this->db->select_max('cast(substr(`column_name`,3) as unsigned)','max_id'); $this->db->get('table_name'); The second parameter is to rename the resulting field

Categories : Mysql

Unable to pass an address of array of type char *[2] to function taking char ***
char *array[2] = {"string", "value"}; is an array with 2 elements of char *. Using array as an address results to a pointer to the first element, i. e. of type char **. Using &array results to a pointer to the same place, but of type char *(*)[2] (not sure if the spelling is right). This is not the same as a char *** - the representation in memory is completely different. To be more verbose, +++++++++++++++++++++++ + array[0] + array[1] + +++++++++++++++++++++++ this is the array. char ** p1 = array; // is a pointer to the first element, which in turn is a pointer. char *(*p2)[2] = &array; // is a pointer to the whole array. Same address, but different type, i. e. sizeof(*p1) != sizeof(*p2) and other differences. char ***p3 = &p1; // Now, p1 is a different pointer va

Categories : C

char pointers, char arrays, and strings in the context of a function call
The char[] signature in the parameter is exactly the same as char*. In C++, it is illegal to convert a string constant char const* (the string "Kacy") to a char* because strings are immutable. Your second example compiles because the name is an actual array. There is no change to char*. As a solution, change your parameter to take a const string array: Student(char const name[]); which again is the same as String(char const *name); though you're better off using std::string: #include <string> class String { public: String(std::string name); };

Categories : C++

How can I write a function boolean succeeds(char a, char b, String s)? using s.equals(""), s.charAt(0), s.substring(1)
Something like this should work. I have not compiled this. Hopefully it gets you in the right direction, even with possible syntax errors. public boolean succeeds(char a, char b, String s){ boolean sawFirst= false; for(int i=0;i<s.length();i++){ if(!sawA){ if(s.charAt(i)==b) sawFirst = true; } else{ if(s.charAt(i)!=a) return false; else sawFirst= false; } } return true; }

Categories : Java

Why doesn't C function with char** param set value of a pointer to char[] arg
The problem is that a pointer to an array is not compatible with a pointer to a pointer. They are different things. And it's a good thing too, because this is meant to catch errors like the one in your code. What you are doing is basically this: unsigned char szrecordid[28]; szrecordid = malloc(i * sizeof **value); You should be able to see the problem; you're trying to assign a pointer to an array.

Categories : C

declaration of C function 'void msgBox(const char*, const char*)' conflicts with previous declaration
It is illegal to have two functions with the same name that have C language linkage. 7.5p6 At most one function with a particular name can have C language linkage.

Categories : C++

is char** x = (char**) arg equivalent to reinterpret_cast(const_cast(arg) )?
Yes they are basically the same except the c++ style cast shows the reader of the code that you are doing some weird stuff while its harder to notice with the c style. Its legal yet as always its highly suspect when a const incoming parameter is being cast as non const.

Categories : C++

C++ Small char to hex function?
An example of bin2hex would look like this: #include <string> #include <iostream> std::string bin2hex(const std::string& input) { std::string res; const char hex[] = "0123456789ABCDEF"; for(auto sc : input) { unsigned char c = static_cast<unsigned char>(sc); res += hex[c >> 4]; res += hex[c & 0xf]; } return res; } int main() { std::string example = "A string"; std::cout << "bin2hex of " << example << " gives " << bin2hex(example) << std::endl; }

Categories : C++

Calling a C dll function which gets char** from C#
Generally, your pinvoke signature would be static extern void GetSectionData(string name, out string address, out int size); but: at 'adress' parameter, you may need to indicate the relation to 'size' by [MarshalAs] attribute and proper SizeIndex value. If you change the 'out string' to 'out char[]' then surely it will be required, but if you use string and if your returned string is a normal null-terminated string, I think it will not be necessary if the function allocates the memory for address array, you might encounter some problems as the usage of the function will assume that the caller must know how to free it.. please see i.e. http://stackoverflow.com/a/1932956/717732 or http://stackoverflow.com/a/12274007/717732 - the main problem is that there are really many ways to allocat

Categories : C#

Cant read char * from c function, using VB
This doesn't look right (Variant): extern "C"{Variant _stdcall Get_Receivedata(void);} Anyway, I really recommend that you use a parameter instead. Something like this... C++: extern "C"{void _stdcall Get_Receivedata(char** data);} VB: Declare Function Get_Receivedata Lib "rapdll.dll" (ByRef Data As String)

Categories : C

function in C to print char content
Remove the [] when passing the character array to the function. Hence your function call will look like this: printChar(ChAr); This will solve the compiler error. In addition, use strlen(ChArr) in the function definition instead of sizeof(ChArr). Only then will all the characters in the array be displayed.

Categories : C

char * to wchar_t * function implementation
As a starting point; gcc will give you platform dependent wchar type/size as follows: echo "" | gcc -E - -dM | grep WCHAR #define __WCHAR_MAX__ 2147483647 #define __WCHAR_MIN__ (-__WCHAR_MAX__ - 1) #define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2 #define __WCHAR_TYPE__ int #define __SIZEOF_WCHAR_T__ 4 A resource suggests: "Both C and C++ introduced fixed-size character types char16_t and char32_t in the 2011 revisions of their respective standards to provide unambiguous representation of 16-bit and 32-bit Unicode transformation formats, leaving wchar_t implementation-defined."

Categories : C++

Passing char array to function
static const char* hello_str = "hello" will do it. Replace sizeof() with strlen. Maybe this should have been a comment as I am not explaining the fundamentals of pointers, but I actually do not see a point :) in doing that as there are plenty of info on that subject elsewhere.

Categories : C++

Passing char arrays to a function
This piece of the code works well. Post if there is still any problem. #include<stdio.h> #include<string.h> char* get_request_type(char *buffer) { char *p; printf("----%s ",buffer); p = strtok(buffer, "|"); //fprintf("%s--->",p); return p; } int main() { char buffer[30] = "test|something"; fprintf(stdout, "buffer: %s ", buffer); //<-- looks great but needs parsing char* request_type = get_request_type(buffer); //<-- No error here fprintf(stdout, "request_type: %s ", request_type); return 0; }

Categories : C

Returning char array from function
In this function: void GetFileContents(const char* FilePath, size_t& size, char* data){ file_mapping fm(FilePath, read_only); mapped_region region(fm, read_only); data = static_cast<char*>(region.get_address()); ... } fm and region are objects with automatic storage duration, lifetime of which ends when the execution goes out of scope. Using their internals after these objects are destructed yields undefined behavior. Another problem is that you are actually trying to change the pointer itself, meaning that your function should take char** dataPtr and you should call GetFileContents(FilePath, size, &data);. But since you are using C++, you should consider using std::string or since you're not working with null-terminated string, std::vector<char> mi

Categories : C++

char pointer as function parameter
Because you print the size of the pointer, and not what it points to. Arrays decays to pointers, and as soon as you pass it to a function you have a pointer instead, and loose all size information of the original array.

Categories : C

Passing char matrix to C function
AS @IgorTandetnik said define like this char* data[]= {matrix[0], matrix[1], matrix[2], matrix[3]}; someFunc(data, 2, 3); // works fine array of character pointers initialized with the each row of matrix and then passed this as argument test code: #include<stdio.h> void someFunc (char** characters, int from, int to); char matrix[4][4] = { { 'a', 'e' , 'i', 'm'}, { 'b', 'f' , 'j', 'n'}, { 'c', 'g' , 'k', 'p'}, { 'd', 'h' , 'l', 's'} }; main() { char* data[]= {matrix[0], matrix[1], matrix[2], matrix[3]}; someFunc(data, 2, 3); } void someFunc (char** c , int from, int to) { int i=0,j=0; for(i=0;i<4;i++) for(j=0;j<4;j++) printf("%c ",c[i][j]); //printf("%c",*(c[i]+j));

Categories : C

SUBSTR() in MYSQl
It's this query (assuming your 'remove' is update data in DB): UPDATE tablename SET colname=SUBSTR(colname, 1, CHAR_LENGTH(colname)-1) -this will remove 1 symbol from end of string. (so, SUBSTR(colname, 1, CHAR_LENGTH(colname)-2) for 2 sumbols - you've updated) (upd. there are suggestions for LEFT() function, it's better. I will not repeat that code, however).

Categories : Mysql

Get last field using awk substr
Use the following: awk -F "/" '{print $NF}' input as NF refers to the number of fields of the current record, printing $NF means printing the last one. Test $ cat a /home/parent/child1/child2/child3/filename /home/parent/child1/child2/filename /home/parent/child1/filename $ awk -F"/" '{print $NF}' a filename filename filename

Categories : Unix

Prototype and substr
Well it looks like you are trying to perform a replacement, so you should be using replace() instead of substr(): String.prototype.replaceme = function() { return this.replace("&lt;", "<").replace("&gt;", ">"); } That being said, there are probably better ways to decode HTML entities.

Categories : Javascript

Should I use str_replace instead of substr?
str_replace() can fit for what you are trying to do, but his method can work as well. He just left out a parameter on substr(). His code should work with that parameter added back in (assuming that you always have a 2-character value in the ref=ab part of the string: function WOKI_Change_Url($x){ $y = substr($x, 29); $y = substr($y, 0, -2); //the 0 here tells it to use the whole string, minus the last two chars; without the zero, this would muck things up a lot return "http://www.dsqce.com/click-111111-1111XX111?url=http%3A%2F%2Fwww.affiliatecompa.com" . $y . 'laik'; } As to str_replace(), that too could work if you know the value of what you are trying to replace, but things get complicated with escaping using str_replace. If it is always exactly ref=ab to be replaced with

Categories : PHP

SUBSTR and add "-" to a number
You can use CONCAT on SUBSTR, like this: SELECT CONCAT( SUBSTR(DriveID,1,1) , '-' , SUBSTR(DriveID,2,5) , '-' , SUBSTR(DriveID,6,2) ) FROM test Demo on sqlfiddle.

Categories : Mysql

Passing pointer to char array to function
*Edited .. made a mistake You are not declaring an array of char* you are declaring an array of char. Adding asterisk to your variable declaration and removing the & should make it work: void printit(char** arr){ string tmp(arr[0]); cout<<tmp<<endl; } char* a[20] = {"hello"}; printit( a );

Categories : C++

Getting trash data in char* while using it as buffer in function
DLL_PingConnection(var avXml:PChar):Boolean; This is not a full declaration. Obviously, it is a function since it has a Boolean return type. But does it also declare a calling convention as well - stdcall (__stdcall in C/C++) or cdecl (__cdecl in C/C++)? If not, then it is using Delphi's default register convention instead (which is __fastcall in Borland/CodeGear/Embarcadero C++ compilers only, but has no equivalent in any other C/C++ compiler). Your existing typedefs are using your C++ compiler's default calling convention, which is usually __cdecl. Calling convention mismatches are the most common problem with using DLLs, as it causes mismanagement of the call stack, which affects how parameters are passed, accessed, and cleaned up. Also, what version of Delphi was the DLL wr

Categories : C++

Does char* cause memory leak if passed to a function
free() must only be called if malloc(), calloc() or realloc() was used to allocate memory. This is not the case in the posted code so calling free() is unrequired. The "asd" is a string literal and exists for the lifetime of the program (has static storage duration).

Categories : C

returning array of char pointers from a function (c++)
Returning objects allocated in the automatic storage (also known as "stack objects") from a function is undefined behavior. When you need to return an array in C, you have three options: Return an object allocated in the static storage area, Return an object allocated in the dynamic storage area, or Take a buffer and max size, and return the actual size of the array. The first option is rarely applicable, because it makes your function non-reentrant. The third option is widespread, but it has limitations: when you must return more data than fits into the buffer, the API needs to be called multiple times. This leaves us with option number two: use new to allocate the memory that you are returning, copy the data into it, and return the result to the caller. It is now caller's responsibi

Categories : C++

c++ pass char array to function and change it
When you pass an argument to a function, it's normally passed by value, meaning its value is copied. If you want to change it you have to pass it by reference. The same goes for pointers, if you want to change a pointer then you need to pass it by reference as well: void change_array(const char*& target) { ... }

Categories : C++

Pass char * to delphi dll function/procedure
You cannot call that function from C++. The Delphi string type is a private Delphi type. For interop you'll want to use a pointer to null-terminated array of characters. In C++ that is char*, and in Delphi that is PAnsiChar. What's more, your Delphi function uses the register calling convention which is a register based fastcall convention. Again, you cannot access that from other languages. You'll need to use one of the standard calling conventions. The function pointer in your C++ code already passes a char*, and uses the cdecl calling convention. So you just need to make the Delphi function match: function a(param: PAnsiChar): integer; cdecl; The above declaration is compatible with the C++ code in your question. If you prefer to use stdcall then you need to change both Delphi a

Categories : C++

external dll, static function and char* relation in C++
It sounds like you're doing an "strcat()" on an uninitialized string. Methinks that might cause a segmentation violation, eh? Q: What happens if you substitute "strcpy()"? Do you still experience the problem?

Categories : C++

Size of char pointer array from function
It's because char *messages[] is just syntactic sugar for char **messages, so you're just getting the size of a pointer, not the size of your whole array. You can't, without passing the size along as another parameter. You should check out the comp.lang.c FAQ section on Arrays & Pointers.

Categories : C

strpos and substr on String
Just use a preg_match: #([d]*)s([a-zA-Zs]*)s([d]*)s([a-zA-Zs]*)# Example output: array ( 0 => '20 Paul Mark Zedd 10203040506 SoftwareEngineering', 1 => '20', 2 => 'Paul Mark Zedd', 3 => '10203040506', 4 => 'SoftwareEngineering', )

Categories : PHP

How to substr or strpos this character
you need this regex /httpq://([d+]{1,3}[.|/])+[^/]+/(S+)/.*/ example: $str = "httpq://199.91.153.63/7otxr1alp53g/kfz254yae7cw8fb/1-Yes%26metalica.mp3"; $regex = "/httpq://([d+]{1,3}[.|/])+[^/]+/(S+)/.*/"; echo preg_replace($regex, "$2", $str);

Categories : Misc

String Calculator substr()
You can just reverse the procedure so that recursion will move from left to right: #include<iostream> #include<sstream> #include<string> #include<cctype> #include<cmath> using namespace std; enum {PLUS='+',MINUS='-',MULT='*'}; int numberValue(string &expr) { istringstream is(expr); int value = 0; is >> value; return value; } int expressionValue(string &expr) { for(int i=expr.length()-2;i>=0;i--) //assuming last character will not be an operand { { switch(expr.at(i)) { case PLUS: return expressionValue(expr.substr(0,i)) + expressionValue(expr.substr(i+1,expr.length()-i-1)); case MINUS: return expressionValue(expr.substr(0,i)) - expressionValue(expr.substr(i+1,expr.length()-i-1));

Categories : C++

Javascript substr problems
The second parameter to the substr function is how many characters to extract (length). The first parameter sets where to start from. You can read more here in the documentation. So your line of code : listener.substr( 9, 10 ); basically says "give me 10 characters from the 9th index". However, since there simply isn't 10 characters after the 9th index, the command will return everything that it can which is the rest of the string. To extract only one character after the 9th index all you'll have to do is use this command: listener.substr( 9, 1 ); Alternatively, if you want to extract a string between two indexes, you can use the substring() function: listener.substring( 9, 10 );

Categories : Javascript

strlen, rand and substr in PhP
The third parameter of substr is the length of the string, so it should be 1: $name = "Freddy"; $len = strlen($name); $rand = rand(0, $len - 1); echo substr($name ,$rand, 1);

Categories : PHP

Equivalent of substr for raw vectors
This is a C implementation library(inline) subraw <- cfunction(c(x="raw", i="integer", j="integer"), " int n = INTEGER(j)[0] - INTEGER(i)[0] + 1; SEXP result; if (n < 0) Rf_error("j < i - 1"); result = Rf_allocVector(RAWSXP, n); memcpy(RAW(result), RAW(x) + INTEGER(i)[0] - 1L, n); return result; ") with the usual caveats about missing sanity checks (e.g., i, j scalar and not NA, i > 0; j <= length(x), etc.). In action > xx = readBin("~/bin/R-devel/lib/libR.so", raw(), 6000000) > length(xx) [1] 5706046 > length(subraw(xx, 1L, length(xx))) [1] 5706046 > system.time(subraw(xx, 1L, length(xx))) user system elapsed 0.000 0.000 0.001 subraw(xx, 10L, 9L) returns raw(0).

Categories : R



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.