天道酬勤,学无止境

string

How to substring in jquery

Question How can I use jquery on the client side to substring "nameGorge" and remove "name" so it outputs just "Gorge"? var name = "nameGorge"; //output Gorge Answer1 No jQuery needed! Just use the substring method: var gorge = name.substring(4); Or if the text you want to remove isn't static: var name = 'nameGorge'; var toRemove = 'name'; var gorge = name.replace(toRemove,''); Answer2 Using .split(). (Second version uses .slice() and .join() on the Array.) var result = name.split('name')[1]; var result = name.split('name').slice( 1 ).join(''); // May be a little safer Using .replace(). var

2022-07-11 09:54:28    分类:技术分享    javascript   jquery   string

C# String Replace safely

Question do you have any ideas or tips how to replace a string safely? Example: string Example = "OK OR LOK"; Now i want to replace "OK" with true and "LOK" with false. Example = Example.Replace("OK", "true"); Example = Example.Replace("LOK", "false"); Now the Result is: Example = "true or Ltrue"; The Result should be: Example ="true or false"; I understand the problem, but i have no idea how to fix this. Thanks Answer1 You could replace the longest strings first, f.e. with this method: public static string ReplaceSafe(string str, IEnumerable<KeyValuePair<string, string>> replaceAllOfThis) {

2022-07-11 09:54:17    分类:技术分享    c#   string   replace

Replace X with Y and Y with X in a single Regular Expression

Question Say I have the following: var strRandomString = "I have 2 apples and 6 oranges and 3 grapes"; Now I want to replace the word "apples" with the word "oranges" and vice-versa. Order is not fixed and replace should be global. This makes the end result: document.write(strRandomString) \\"I have 2 oranges and 6 apples and 3 grapes"; Currently, the best way I can think to do this is: strRandomString=strRandomString.replace("apples","*******"); strRandomString=strRandomString.replace("oranges","apples"); strRandomString=strRandomString.replace("*******","oranges"); Is there a way to do this

2022-07-11 09:38:57    分类:技术分享    javascript   regex   string

parse utf code in vbscript

Question Is there a way to parse utf codes in vbscript? What I'd like to do is replace all codes like "\u00f1" in a string for its corresponding character. Answer1 The Unescape function does that*, only it requires that the Unicode characters are encoded in the %u***xxxx* format. So, you'll need to replace the \u***xxxx* codes with their **%u***xxxx* equivalents first. Here's an example: str = "\u0044\u006F \u0063\u0061\u0074\u0073 \u0065\u0061\u0074 \u0062\u0061\u0074\u0073\u003f" Set re = New RegExp re.Pattern = "\\(u[a-f\d]{4})" re.IgnoreCase = True re.Global = True str2 = Unescape(re

2022-07-11 09:37:50    分类:技术分享    string   vbscript   utf

Assigning a character array in Fortran

Question I'm having to write a subroutine that can be called both by C and by Fortran. This subroutine takes a file name as one of its arguments. I know that to interoperate nicely with C, the ISO C binding recommends using character arrays for interoperation. The question I have is: is there such a thing as a character array literal that's easy to write? I have a subroutine like this: subroutine my_sub(char_array) use iso_c_binding, only: c_char char(kind=c_char, len=1), dimension(:), intent(in) :: char_array ... end subroutine my_sub Is it possible to invoke this with something like: call my

2022-07-11 09:37:23    分类:技术分享    string   fortran   fortran-iso-c-binding   character-arrays

getting string between 2 characters in python

Question I need to get certain words out from a string in to a new format. For example, I call the function with the input: text2function('$sin (x)$ is an function of x') and I need to put them into a StringFunction: StringFunction(function, independent_variables=[vari]) where I need to get just 'sin (x)' for function and 'x' for vari. So it would look like this finally: StringFunction('sin (x)', independent_variables=['x'] problem is, I can't seem to obtain function and vari. I have tried: start = string.index(start_marker) + len(start_marker) end = string.index(end_marker, start) return

2022-07-11 09:33:57    分类:技术分享    python   string   function   character   extraction

Substring after a space

Question I want to split a string and get the value after the space. I can get the value before space but how to get the string after space. DECLARE @string varchar(20) SELECT @string = 'Test Name' SELECT SUBSTRING(@string, 0, CHARINDEX(' ', @string)) Edit: I am using SQLServer 2012 Answer1 Here's a version using SUBSTRING and CHARINDEX for versions of SQL SERVER prior to SQL Server 2016 when STRING_SPLIT was introduced. Either of the following works: SELECT SUBSTRING(@string, CHARINDEX(' ', @string) +1, 20) SELECT SUBSTRING(@string, CHARINDEX(' ', @string) +1, DATALENGTH(@string) - CHARINDEX(

2022-05-17 05:19:05    分类:技术分享    sql-server   string   sql-server-2012   substring

converting an array of null terminated const char* strings to a std::vector< std::string >

Question I have a Visual Studio 2008 C++ function where I'm given an array of null-terminated strings const char* and a count of the number of strings in that array. I'm looking for a clever way of turning an array of const char* in to a std::vector< std::string > /// @param count - number of strings in the array /// @param array - array of null-terminated strings /// @return - a vector of stl strings std::vector< std::string > Convert( int count, const char* array[] ); Boost is fine, STL is fine. Answer1 Something like this?: vector< string > ret( array, array + count ); Answer2 Try this:

2022-05-17 05:17:08    分类:技术分享    c++   string   stl   vector

'java.lang.String' is deprecated in Android

Question I have write simple TAG like this: private static final String TAG = "MainActivity"; String is deprecated Is there any alternative way available to use String? Answer1 As per comment in this java-lang-string-is-deprecated-in-android-studio question, Remove folder .AndroidStudioX.X in your User folder and Restart IDE. NOTE: AndroidStudioX.X means if you are using Android Studio version 3.4 then .AndroidStudio3.4 will be there. Path will be like Windows : C:\Users\<PCNAME>\.AndroidStudio3.4 Linux/Ubuntu : /home/yourname/.AndroidStudio3.4 Hope it will be helpful to you.

2022-05-17 03:27:40    分类:技术分享    android   string   deprecated

Simple Regex problem that I just CAN'T figure out

Question I have quite a simple problem, I need to parse through this string: "user_id" => "BXoVWYg-T_QS" And grab only the BXoVWYg-T_QS I have used regex thus far to grab that much from a much larger string, but I can't figure out how to get it down to just the contents of the user_id string This is the regex I have so far: "user_id" => ".*" Please help! Update I have a string of html that I am trying to parse through for an iPhone app in objective-c. If I can just get the regex syntax down, my problems will be solved Answer1 "user_id" => "([^"]*)" Answer2 You need to indicate your capture

2022-05-17 02:58:35    分类:技术分享    iphone   objective-c   regex   string